Prepare for Your Docker Interview: Basic to Advanced Questions
This comprehensive guide covers 30 essential Docker interview questions with detailed answers, organized by difficulty level. Whether you’re a fresher, have 1-3 years of experience, or are a senior professional with 3-6+ years, these questions will help you demonstrate your Docker expertise across conceptual, practical, and scenario-based topics.
Basic Docker Interview Questions (1-10)
1. What is Docker and how does it work?
Docker is a platform that uses containerization to package applications with their dependencies into isolated environments called containers. Containers share the host OS kernel but run in isolated user spaces, making them lightweight and portable across different systems.[1][3]
2. What are the main components of Docker?
Docker has three main components: Docker Client (performs build and run operations), Docker Host (runs the daemon that manages containers and images), and Docker Registry (stores Docker images, like Docker Hub).[3]
3. What is a Docker container?
A Docker container is a runnable instance of a Docker image that includes the application and all its dependencies. It shares the host kernel, enabling efficient resource utilization and isolation.[2][5]
4. What is a Docker image?
A Docker image is a lightweight, standalone, executable package that includes everything needed to run a piece of software: code, runtime, libraries, and environment variables. Images are built from Dockerfiles.[1][5]
5. What command lists all Docker containers including stopped ones?
Use docker ps -a to list the status of all Docker containers, both running and stopped.[3][5]
6. How do you check the Docker client and server versions?
Run docker version to check both client and server versions. For server version only, use docker version --format '{{.Server.Version}}'
7. What is the difference between docker run and docker create?
docker create creates a container but doesn't start it, while docker run creates and starts the container immediately.[2]
8. What is a Dockerfile?
A Dockerfile is a text file containing instructions to build a Docker image. It defines the environment layer by layer using commands like FROM, RUN, COPY, and CMD.[1]
9. What command starts a stopped Docker container?
Use docker start <container_id> to start a stopped container.[4]
10. What does the -d flag do in docker run?
The -d flag runs the container in detached mode, allowing it to run in the background without attaching to the terminal.[4]
Intermediate Docker Interview Questions (11-20)
11. What is the difference between CMD and ENTRYPOINT in a Dockerfile?
CMD provides defaults for an executing container, while ENTRYPOINT configures the container as an executable. ENTRYPOINT cannot be overridden by arguments, but CMD can.[2]
12. What is the difference between COPY and ADD in a Dockerfile?
COPY is used to copy files from the host to the container, while ADD can also handle URLs and automatically extract tar archives.[2]
13. What are Docker volumes and why are they used?
Docker volumes provide persistent storage for containers. Data in volumes survives container deletion, unlike container filesystem data.[1]
14. What is the difference between "EXPOSE" and "publish" in Docker?
EXPOSE documents the port the container listens on in the Dockerfile, while -p or --publish actually maps that port to the host.[2]
15. How do you stop a running Docker container?
Use docker stop <container_id> to gracefully stop a container. It sends a SIGTERM signal and waits for cleanup.[4]
16. What command kills a Docker container immediately?
docker kill <container_id> sends a SIGKILL signal to immediately terminate the container without cleanup.[4]
17. What is a Docker registry?
A Docker registry is a storage and distribution system for Docker images. Public registries like Docker Hub host public images, while private registries store proprietary ones.[3]
18. How do you access a shell inside a running Docker container?
Use docker exec -it <container_id> /bin/bash to get an interactive shell in a running container.[6]
19. What happens to data when a Docker container exits?
Data stored in the container's writable layer is lost when the container is deleted, unless persisted using volumes or bind mounts.[5]
20. In a Flipkart deployment scenario, how would you run a container with limited memory?
Use docker run -m 512m <image> to limit container memory to 512MB, preventing it from consuming excessive host resources.[2]
Advanced Docker Interview Questions (21-30)
21. What is Docker Compose and what file does it use?
Docker Compose is a tool for defining and running multi-container Docker applications using a YAML file called docker-compose.yml.[6]
22. Explain Docker build cache and how it works.
Docker build cache speeds up image builds by reusing layers from previous builds when Dockerfile instructions haven't changed.[2]
23. What is an orphan volume and how do you remove it?
An orphan volume is a volume not referenced by any container. Remove it with docker volume prune after confirmation.[2]
24. How does Docker handle networking between containers?
Docker provides default bridge networking. Containers can communicate using container names as DNS hostnames on the same network.[1]
25. What is the ONBUILD instruction in Dockerfile?
ONBUILD sets instructions to execute when the image is used as a base for another image, useful for creating reusable base images.[2]
26. In a Paytm microservices scenario, how would you control service startup order in Docker Compose?
Use depends_on in docker-compose.yml to define startup dependencies between services, ensuring databases start before applications.[2]
27. What command removes all stopped containers, unused networks, and dangling images?
docker system prune removes stopped containers, unused networks, build caches, and dangling images to free up space.[3]
28. How do you transfer a Docker image between machines without a registry?
Save the image with docker save -o image.tar <image>, transfer the tar file, then load with docker load -i image.tar.[2]
29. For a Zoho SaaS application, how would you make Docker Compose production-ready?
Remove volume bindings, add restart policies, configure log aggregation services, and bind to specific host ports in docker-compose.yml.[4]
30. What is the default CPU limit for a Docker container?
Docker containers have no default CPU limit; they can use all available host CPU unless limited using --cpus or --cpu-shares flags.[2]
# Example production-ready Dockerfile for a web app
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
USER node
CMD ["npm", "start"]
Master these Docker interview questions to showcase your skills from basic container management to advanced orchestration. Practice hands-on with Docker commands and Dockerfiles to confidently handle any interview scenario.