5

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?

1
  • It does seem like docker inspect is the proper tool to inspect running containers. What's wrong with using that? Do you want to talk to the Docker API directly? Commented Oct 27, 2016 at 6:35

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.