Docker run vs docker create: Key Differences and Usage
docker run command creates and starts a container immediately, combining creation and execution in one step. In contrast, docker create only creates a container without starting it, allowing you to start it later with docker start.Quick Comparison
This table summarizes the main differences between docker run and docker create.
| Factor | docker run | docker create |
|---|---|---|
| Action | Creates and starts a container immediately | Creates a container but does not start it |
| Container State After Command | Running | Created but stopped |
| Use Case | Quickly run containers in one step | Prepare containers for later start or configuration |
| Command Syntax | docker run [OPTIONS] IMAGE [COMMAND] [ARG...] | docker create [OPTIONS] IMAGE [COMMAND] [ARG...] |
| Starting Container | No extra step needed | Requires docker start to run |
| Output | Container ID and logs if attached | Container ID only |
Key Differences
The docker run command is a convenient shortcut that combines creating a container and starting it immediately. When you use docker run, Docker sets up the container environment, allocates resources, and launches the container process in one go. This is useful when you want to quickly start a container and interact with it or run a task.
On the other hand, docker create only sets up the container but leaves it stopped. This means the container exists on your system but is not running yet. You can later start it with docker start. This approach is helpful when you want to prepare containers ahead of time, configure them, or control exactly when they start.
Another difference is in output and behavior: docker run can attach to the container's output and show logs or interactive prompts, while docker create only returns the container ID without starting or attaching to it.
Code Comparison
docker run --name mynginx -d nginx
docker create Equivalent
docker create --name mynginx nginx docker start mynginx
When to Use Which
Choose docker run when you want to quickly create and start a container in one step, especially for short-lived tasks or interactive sessions.
Choose docker create when you want to prepare containers ahead of time without starting them immediately, or when you need to configure or inspect containers before running.
This separation gives you more control over container lifecycle and is useful in scripting or complex workflows.
Key Takeaways
docker run creates and starts containers immediately in one step.docker create only creates containers without starting them.docker create when you want to prepare containers before running.docker run is best for quick, one-step container execution.docker create requires docker start.