Skip to content
BENIBIX Learn

docker run

Infrastructure📦 ContainersRuntimes and Tools

Also known as docker run Command, docker container run, Run a Container

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

Think of it like

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

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.

Why it matters

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

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 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.
docker run is the first arrow. It turns an image into a new running container.

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.

Key takeaways

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

Compare