Interview Q&A / Docker & Kubernetes

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is the difference between docker compose up and docker compose run?

SHORT ANSWER

up creates and starts all services (or those named) as defined, with ports and dependencies. run starts a one-off container for a single service with a command you give, then exits, and does not publish ports by default.

Explain it simply

up opens the whole restaurant: kitchen, counter, waiters. run calls just one chef for a single task, such as cleaning a tandoor, and then he goes home.

docker compose up -d builds if needed and starts every service, wiring networks, volumes and published ports. docker compose run web python manage.py migrate starts a new temporary container from the web service definition, runs that command instead of the default, and starts the services it depends on. Differences: run does not publish the service's ports unless you add --service-ports, it overrides the command, and it creates a separate container each time, so use --rm to remove it afterwards.

Typical uses of run: database migrations, tests, seeding data, a debugging shell.

Example

bash
docker compose up -d                       # whole stack
docker compose run --rm web python manage.py migrate
docker compose run --rm web sh             # debugging shell
docker compose run --service-ports web     # publish ports as well

What to say in the interview

"up starts the full stack as defined. run launches a one-off container for one service with a custom command, without publishing ports by default, which I use for migrations, tests and shells with --rm."

Common mistakes

  • Forgetting --rm and collecting many stopped one-off containers.

#docker-compose#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.