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?

  • Dockernized Nginx + (Rails+Unicorn)+Redis+PostgreSQL:connect() failed (111: Connection refused)
  • How to mount docker volume into my docker project using compose?
  • Single Docker Image with multiple Softwares or Separate images for separate software
  • Build failed while appending line in source of docker container
  • Can Jprofile connect to JVM running in docker
  • docker container not able to write on host machine
  • docker-compose oci runtime error starting container process caused connection reset by peer
  • Not able to access Kibana running in a Docker container on port 5601
  • docker -v command doesn't mount files in a directory in Linux
  • How to Bootstrap from Workstaion to Docker conatiner?
  • What are the best practices for tagging Docker Hub versions
  • Docker - Replacement for `dockerd` on Mac
  • One Solution collect form web for “Reconstruct docker run command parameters from container”

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.