# docker run

> The command that makes a new box from an image and starts it.

**Field:** Infrastructure  
**Category:** Containers  
**Also known as:** docker run Command, docker container run, Run a Container

## Think of it like

Think of it like pressing play. The same song starts fresh each time.

## Definition

docker run is the command that makes a new container from an image and starts it. If the image is not on the machine yet, it downloads it first. Flags set how the container runs: -d runs it in the background, -p publishes a port, and --name gives it a name. Each run makes a fresh container. Changes made inside one are not seen by the next, unless they are kept in a volume.

## Example

Jack types docker run -d -p 8080:80 nginx. Docker downloads the image, starts the web server in the background and prints the new container's ID.

## Example code

```console
$ docker run --rm hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.
```

The --rm flag deletes the container when it ends. The message comes from inside it.

## Why it matters

It is the first command most people learn. Nearly every way of starting a container comes back to it.

## Common mistake

Typing docker run again to get back into a box. That makes a second box. Use docker exec to reach the first one.

## Three principles

- **New every time.** Each run makes a fresh container.
- **Pulls if needed.** Downloads the image when it is missing.
- **Flags shape it.** -d, -p, --name and more.

## Related terms

- [Docker](https://learn.benibix.com/term/infrastructure/docker)
- [Container](https://learn.benibix.com/term/infrastructure/container)
- [Container Image](https://learn.benibix.com/term/infrastructure/container-image)
- [docker exec](https://learn.benibix.com/term/infrastructure/docker-exec)
- [Container Port Mapping](https://learn.benibix.com/term/infrastructure/container-port-mapping)
- [Container Restart Policy](https://learn.benibix.com/term/infrastructure/container-restart-policy)

## Told apart from

- [docker run vs docker exec](https://learn.benibix.com/compare/docker-run-vs-docker-exec): People think docker run takes you back into a container, and it does not. docker run always makes a new container from an image. docker exec runs a command in one that is already running. Type docker run twice and you have two containers, each with its own files.

![An image on the left. An arrow labelled docker run leads to a running container. A side arrow labelled docker exec opens a shell inside it. Another arrow leads to a stopped container, and a curved arrow labelled restart policy leads back to running.](https://learn.benibix.com/diagrams/inf4-container-life.svg)

---

Source: https://learn.benibix.com/term/infrastructure/docker-run
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
