Get docker run command for container

2019-02-17 02:07发布

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.

标签: docker
1条回答
Root(大扎)
2楼-- · 2019-02-17 02:46

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.

查看更多
登录 后发表回答