docker run Explained

What docker run does, with an example.

Published November 7, 2026

docker run creates a new container from an image and starts it. It combines docker create and docker start, and is the command you use most.

How it works

Common flags: -d (detached), -p host:container (publish port), -v (mount a volume), -e (environment variable), --name, --rm (remove when it exits) and -it (interactive terminal).

If the image is not local, Docker pulls it first.

Try it

docker run -d -p 8080:80 --name web nginx
Unable to find image 'nginx:latest' locally
a1b2c3d4e5f6
docker ps
a1b2c3 nginx Up 3 seconds 0.0.0.0:8080->80/tcp

Practical examples

Web server

docker run -d -p 8080:80 --name web nginx

Interactive shell, removed on exit

docker run --rm -it ubuntu bash

With a volume and env var

docker run -d -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=secret -p 5432:5432 postgres:16

Limit resources

docker run -d --memory=512m --cpus=1 myapp

Common mistakes

  • Forgetting -d and tying up the terminal.
  • Using :latest in production.
  • Putting secrets directly on the command line.

Key takeaways

  • docker run creates a new container from an image and starts it.
  • Run docker <command> --help for all options.
  • Clean up unused resources regularly.

FAQ

docker run vs start?

run creates a new container; start restarts an existing one.

Where can I see all options?

Run the command with --help.

More General articles