Get the docker launch command for the container

I have a container that I created, but I can’t remember the exact docker run that I used to run it. Is there any way I can get it?

This is not the same as See the full container start / stop command in Docker . I want to know that this is the complete docker command that spawned the container, not the commands inside the container.

+6
source share
1 answer

You can print most of this information by looking at the output of docker inspect .

For example, you can open a command running inside a container by looking at the Config.Cmd key. If I run:

 $ docker run -v /tmp/data:/data --name sleep -it --rm alpine sleep 600 

I can run later:

 $ docker inspect --format '{{.Config.Cmd}}' sleep 

And we get:

 {[sleep 600]} 

Similarly, the output of docker inspect will also contain information about the Docker volumes used in the container:

 $ docker inspect --format '{{.Volumes}}' sleep map[/data:/tmp/data] 

Of course, you can simply run docker inspect without --format , which will give you a large (100+ lines) fragment of JSON output containing all the available keys, which includes information about port mappings, network configuration, etc.

+8
source

All Articles