Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get docker run command for container

Tags:

docker

I have a container that I created, but I can't remember the exact docker run command I used to kick it off. Is there any way that can be retrieved?

This is not the same as See full command of running/stopped container in Docker What I want to know is the full docker command that spawned the container, not the command within the container.

like image 723
Adam Parkin Avatar asked Jul 17 '15 15:07

Adam Parkin


People also ask

Which is the Run command in a running container?

The docker exec command runs a new command in a running container. The command started using docker exec only runs while the container's primary process ( PID 1 ) is running, and it is not restarted if the container is restarted. COMMAND will run in the default directory of the container.

How do I run a docker container command?

The basic syntax for the command is: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] You can run containers from locally stored Docker images. If you use an image that is not on your system, the software pulls it from the online registry.

How do I run a command in a new container?

Running Commands in an Alternate Directory in a Docker Container. To run a command in a certain directory of your container, use the --workdir flag to specify the directory: docker exec --workdir /tmp container-name pwd.


1 Answers

You can infer most of that information by looking at the output of docker inspect.

For example, you can discover the command started inside the 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 later run:

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

And get:

{[sleep 600]}

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

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

You can of course just run docker inspect without --format, which will give you a big (100+ lines) chunk of JSON output containing all the available keys, which includes information about port mappings, network configuration, and more.

like image 154
larsks Avatar answered Oct 09 '22 14:10

larsks