Interview Q&A / Docker & Kubernetes

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What does docker run -d -p 8080:80 --name web nginx do?

SHORT ANSWER

It starts a container named web from the nginx image in the background (-d) and publishes container port 80 on host port 8080, so http://localhost:8080 reaches nginx.

Explain it simply

Think of a restaurant order slip. The image is the dish, the flags are your instructions: 'pack it to go, call it web, and serve it at counter 8080 even though the kitchen calls that counter 80'.

docker run is really two steps in one: create a container from the image (pulling the image first if it is not on your machine) and start it. -d means detached, so your terminal is returned immediately instead of showing nginx logs. --name gives a friendly name instead of a random one like quirky_turing. -p host:container maps a port on your machine to a port inside the container. Without -p, the container is reachable only from other containers on the same network.

Example

bash
docker run -d -p 8080:80 --name web nginx
docker ps                      # web is listed, PORTS shows 0.0.0.0:8080->80/tcp
curl http://localhost:8080     # returns the nginx welcome page
docker stop web && docker rm web

What to say in the interview

"docker run creates and starts a container from an image, pulling it if needed. -d runs it in the background, --name sets its name, and -p 8080:80 publishes container port 80 on host port 8080. The order is host port first, container port second."

Common mistakes

  • Writing -p 80:8080 the wrong way round: host port comes first.
  • Running the same command twice and hitting a 'name already in use' error because the first container still exists.

#docker#commands

Related questions

Practise more Docker & Kubernetes questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Docker & Kubernetes quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.