Miloš Kroulík
Miloš Kroulík

Reputation: 161

Reconstruct docker run command parameters from container

What's the best way to reconstruct docker run command parameters from existing docker container? I could use docker inspect and use the info found there. Is there any better way?

Upvotes: 5

Views: 1812

Answers (2)

Stefan Winkler
Stefan Winkler

Reputation: 3966

See also this answer which links to a tool which programmatically derives the docker run command from a container.

Upvotes: 0

Elton Stoneman
Elton Stoneman

Reputation: 19184

Not super easy, but you can do it by formatting the output from docker inspect. For a container started with this command:

> docker run -d -v ~:/home -p 8080:80 -e NEW_VAR=x --name web3 nginx:alpine sleep 10m

You can pull out the volumes, port mapping, environment variables, container name, image name and command with:

> docker inspect -f "V: {{.Mounts}} P: {{.HostConfig.PortBindings}} E:{{.Config.Env}} NAME: {{.Name }} IMAGE: {{.Config.Image}} COMMAND: {{.Path}} {{.Args}}" web3

That gives you the output:

V: [{ /home/scrapbook /home   true rprivate}] P: map[80/tcp:[{ 8080}]] E:[NEW_VAR=x PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin NGINX_VERSION=1.11.5] NAME: /web3 IMAGE: nginx:alpine COMMAND: sleep [10m]

Which is a start.

Docker Captain Adrian Mouat has an excellent blog post on formatting the output: Docker Inspect Template Magic.

Upvotes: 5

Related Questions