Docker run vs create

docker run = docker create + docker start.


From docker documentation

The docker create command creates a writeable container layer over the specified image and prepares it for running the specified command. The container ID is then printed to STDOUT. This is similar to docker run -d except the container is never started. You can then use the docker start command to start the container at any point.

This is useful when you want to set up a container configuration ahead of time so that it is ready to start when you need it. The initial status of the new container is created.


docker create command creates a writeable container from the image and prepares it for running.

docker run command creates the container (same as docker create) and starts it.


The other answers have this covered but I thought I'd show the equivalent shell command-lines because it makes it really clear:

$ docker run myimage

is the same as

$ docker start -a $(docker create myimage)

Here, docker create is used to create a container from the named image and outputs the created container id and docker start is used to start the container with that id. The -a option causes the terminal to attach so that the container runs in the foreground which is the default behaviour of docker run.

A container that has been created but never started will have a Created status; this can be seen with docker container ls -a.

Tags:

Docker