What is the docker run command?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Docker topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
docker run creates and starts a new container from an image. It is the most commonly used Docker command, combining docker create and docker start. Syntax: docker run [options] image [command] [args]. Essential options: -d / --detach — run in the background (daemon mode), print container ID; -p 8080:3000 / --publish — map host port 8080 to container port 3000; -e NODE_ENV=production / --env — set environment variable; --name myapp — assign a name (instead of random name); -v /host/path:/container/path / --volume — mount a volume; --rm — automatically remove the container when it exits (great for one-off tasks); -it — interactive terminal (-i keeps stdin open, -t allocates a pseudo-TTY); --network — connect to a specific network; --restart unless-stopped — restart policy; --memory 512m — memory limit; --cpus 1.5 — CPU limit. Example: docker run -d -p 80:3000 -e NODE_ENV=production --name myapi --restart unless-stopped myapp:1.0.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Docker candidates.