0
0
DockerComparisonBeginner · 3 min read

Docker run vs docker create: Key Differences and Usage

The 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.

Factordocker rundocker create
ActionCreates and starts a container immediatelyCreates a container but does not start it
Container State After CommandRunningCreated but stopped
Use CaseQuickly run containers in one stepPrepare containers for later start or configuration
Command Syntaxdocker run [OPTIONS] IMAGE [COMMAND] [ARG...]docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
Starting ContainerNo extra step neededRequires docker start to run
OutputContainer ID and logs if attachedContainer 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

bash
docker run --name mynginx -d nginx
Output
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6
↔️

docker create Equivalent

bash
docker create --name mynginx nginx

docker start mynginx
Output
e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8a9b0c1 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.
Use docker create when you want to prepare containers before running.
docker run is best for quick, one-step container execution.
Starting a container created with docker create requires docker start.