Any way to retrieve the command originally used to create a Docker container?

Related searches

This question seems to have been often asked, but I cannot find any answer that correctly and clearly specifies how to accomplish this.

I often create test docker containers that I run for a while. Eventually I stop the container and restart it simply using docker start <name>. However, sometimes I am looking to upgrade to a newer image, which means deleting the existing container and creating a new one from the updated image.

I've been looking for a reliable way to retrieve the original 'docker run' command that was used to create the container in the first place. Most responses indicate to simply use docker inspect and look at the Config.Cmd element, but that is not correct.

For instance, creating a container as:

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Qwerty123<(*' -e TZ=America/Toronto -p 1433:1433 -v c:/dev/docker/mssql:/var/opt/mssql --name mssql -d microsoft/mssql-server-linux

using docker inspect will show:

$ docker inspect mssql | jq -r '.[0]["Config"]["Cmd"]'
[
  "/bin/sh",
  "-c",
  "/opt/mssql/bin/sqlservr"
]

There are many issues created on github for this same request, but all have been closed since the info is already in the inspect output - one just has to know how to read it.

Has anyone created a utility to easily rebuild the command from the output of the inspect command? All the responses that I've seen all refer to the wrong info, notably inspecting the Config.Cmd element, but ignoring the Mounts, the Config.Env, Config.ExposedPorts, Config.Volumes, etc elements.

There are few utilities out there which can help you.

Give it a try

https://github.com/bcicen/docker-replay

https://github.com/lavie/runlike

If you want to know more such cool tools around docker check this https://github.com/veggiemonk/awesome-docker

docker history, --no-trunc, Don't truncate output ago /bin/sh -c apt-get update && apt-get install 338.3 MB 4b137612be55 6 weeks ago /bin/sh -c #(nop) ADD jessie.tar.xz in / 121 MB 750d58736b4b To see how the docker:apache image was added to a container's base image: CreatedBy, Command that was used to create the image. To save changes to a container, we use commits. Commits. When you create a Docker container, its hostname is automatically generated. For example, when I create a new Ubuntu container, I might get the hostname f7943e42aff0. This is the name that Docker has given to your container. Install what you want on it, and make sure everything works.

Of course docker inspect is the way to go, but if you just want to "reconstruct" the docker run command, you have

https://github.com/nexdrew/rekcod

it says

Reverse engineer a docker run command from an existing container (via docker inspect).

Another way is Christian G answer at

How to show the run command of a docker container

using bash-preexec

docker create, Learn how to create a Docker image by writing a Dockerfile, and use it to run a simple container. Now that you have some source code and a Dockerfile, it's time to build your first image, and make sure the containers launched Run the following command to build your bulletin board image: Get Docker; Get started. To see how the exec command works and how it can be used to enter the container shell, first, start a new container. We’ll use the official MySQL image: docker container run --name my_mysql -d mysql. This will create a container named “my_mysql”. To execute a command inside the container run the following command: docker container exec

I've had the same issue and ended up looking at .bash_history file to find the command I used. This would give you all the docker create commands you'd run;

grep 'docker create' .bash_history

Note: if you ran docker create in that same session you'll need to logout/login for the .bash_history to flush to disk.

Build and run your image, --no-trunc, Don't truncate output. --quiet , -q, Only Command, Description docker image import, Import the contents from a tarball to create a filesystem image docker image pull, Pull an image or a repository from a registry Developers � Use Cases � Play with Docker � Community � Open Source � Docker Captains. $ docker logs [container name] What’s next? After all your feedback, I decided to write the next part of this beginner’s guide. In this article, you will discover how to use docker-compose to create your first client/server-side application with Docker.-> A beginner’s guide to Docker — how to create a client/server side with docker-compose

docker image history, With Docker, you can manage your infrastructure in the same ways you The daemon creates and manages Docker objects, such as images, When you use commands such as docker run , the client sends these A container is defined by its image as well as any configuration options you Get Docker; Get started. Create a new ‘HelloWorld’ image that includes the changes in the first container you ran. To do so, run the docker commit command, replacing <containerid> with the ID of your container: docker commit <containerid> helloworld When completed, you now have a custom image that contains the hello world script. This can be seen with the docker

Docker overview, Docker inspect is a great way to retrieve low-level information on Docker objects. You can pick out any field from the returned JSON in a fairly straightforward manner. So shall we use it to get the IP Address from the dockerhive_datanode? $ docker inspect -f \ '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' \ 75000c343eb7 172.18.0.5

The VOLUME instruction should be used to expose any database storage area, configuration storage, or files/folders created by your docker container. You are strongly encouraged to use VOLUME for any mutable and/or user-serviceable parts of your image. USER. Dockerfile reference for the USER instruction