Interview Q&A / Docker & Kubernetes
Docker & Kubernetes interview questions
Images, containers, Dockerfiles, pods and deployments, from first principles.
Prefer rapid revision? Practise Docker & Kubernetes short interview answers →
- What is Docker Compose and when would you use it?
Docker Compose lets you define a multi-container app, such as a web server, database and cache, in one YAML file and start or stop all of it with one command. It sets up a shared network so services reach each other by name, and it is mainly used for local development, testing and small single-server deployments.
BeginnerIn-depth3 min read - What is the difference between docker compose stop, down and down -v?
stop halts containers but keeps them. down stops and removes containers and networks. down -v also deletes the named volumes, which destroys stored data.
BeginnerQuick answer1 min read - Does depends_on in Docker Compose wait until the database is ready?
By default no. depends_on only controls start order, not readiness. To wait for a healthy service, add a healthcheck and use depends_on with condition: service_healthy.
IntermediateQuick answer1 min read - How do you pass environment variables and secrets into services in Docker Compose?
Use environment: for inline values, env_file: to load a file, and ${VAR} substitution from the shell or a .env file. Keep real secrets out of Git and prefer Compose secrets or an external secret store.
IntermediateQuick answer1 min read - What is docker-compose.override.yml and how is it used?
Compose automatically merges docker-compose.override.yml on top of docker-compose.yml. Teams keep shared settings in the base file and development extras like bind mounts or debug ports in the override.
IntermediateQuick answer1 min read - What is the difference between docker compose up and docker compose run?
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.
IntermediateQuick answer1 min read - How do you run optional services or multiple replicas of a service in Docker Compose?
Assign a service to a profile so it starts only when requested with --profile. For replicas use docker compose up --scale web=3, which requires the service not to publish a fixed host port.
AdvancedQuick answer1 min read