Difference between Running and Starting a Docker container
Explanation with an example:
Consider you have a game (iso) image in your computer.
When you run
(mount your image as a virtual drive), a virtual drive is created with all the game contents in the virtual drive and the game installation file is automatically launched. [Running your docker image - creating a container and then starting it.]
But when you stop
(similar to docker stop) it, the virtual drive still exists but stopping all the processes. [As the container exists till it is not deleted]
And when you do start
(similar to docker start), from the virtual drive the games files start its execution. [starting the existing container]
In this example - The game image is your Docker image and virtual drive is your container.
This is a very important question and the answer is very simple, but fundamental:
- Run: create a new container of an image, and execute the container. You can create N clones of the same image. The command is:
docker run IMAGE_ID
and notdocker run CONTAINER_ID
- Start: Launch a container previously stopped. For example, if you had stopped a database with the command
docker stop CONTAINER_ID
, you can relaunch the same container with the commanddocker start CONTAINER_ID
, and the data and settings will be the same.
run
runs an imagestart
starts a container.
The docker run
doc does mention:
The
docker run
command first creates a writeable container layer over the specified image, and then starts it using the specified command.That is, docker run is equivalent to the API
/containers/create
then/containers/(id)/start
.
You do not run an existing container, you docker exec to it (since docker 1.3).
You can restart an exited container.