What is the difference between Docker run and Docker start?
Understanding the distinction between `docker run` and `docker start` is fundamental for effective Docker container management. While both commands result in a running container, they operate on different states of a container's lifecycle.
Docker run
docker run is a command used to create a new container from a specified image and then start that container. If the image is not available locally, Docker will first pull it from Docker Hub (or another configured registry). This command essentially combines the functionality of docker create (which creates a container) and docker start (which starts a container).
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
# Example: Create and run a new Nginx container, exposing port 80
docker run --name my-nginx -p 80:80 -d nginx
Docker start
docker start is a command used to start one or more stopped containers. It does not create a new container; instead, it brings an existing container (that was previously created using docker create or docker run and then stopped) back to a running state. The container retains its original ID, configuration, and any persistent data volumes.
docker start [OPTIONS] CONTAINER [CONTAINER...]
# Example: Start a previously created and stopped container named 'my-nginx'
docker start my-nginx
Key Differences Summary
| Feature | docker run | docker start |
|---|---|---|
| Action | Creates a new container from an image and starts it. | Starts an existing, stopped container. |
| Container State | A new container is initialized and run. | Container must already exist (was previously created or run). |
| Image Requirement | Requires an image to build the container. | Does not require an image; operates on an existing container by its ID or name. |
| Persistence | Creates a new container ID, filesystem layer, and network stack (unless explicitly reused/named). | Restarts the *same* container with its existing ID, configuration, and state. |
| First Use? | Yes, typically for the first time you launch an application from an image. | No, only for containers that have been run before and subsequently stopped. |
When to Use Which
- Use
docker runwhen you want to deploy a fresh instance of an application from a Docker image, creating a new container. - Use
docker startwhen you have a previously created and stopped container that you want to resume without losing its previous state or configuration.