Prepare for Your Docker Interview: Basic to Advanced Questions
This comprehensive guide features 30 Docker interview questions covering conceptual, practical, and scenario-based topics. Questions progress from basic to intermediate and advanced levels, helping freshers, candidates with 1-3 years experience, and professionals with 3-6 years prepare effectively for Docker-focused interviews at companies like Amazon, Zoho, and Atlassian.
Basic Docker Interview Questions
1. What is Docker?
Docker is an open-source platform that uses containerization to package, deploy, and run applications in isolated environments called containers. Containers include everything needed to run an application, ensuring consistency across different systems.
2. What is the difference between Docker image and Docker container?
A Docker image is a read-only template containing application code, libraries, and dependencies. A Docker container is a runnable instance created from an image, providing an isolated environment for the application.
3. How do you check the version of Docker?
Use the command docker version to check both Docker client and server versions. This displays detailed information about the installed Docker components.
4. What command creates a container from an image?
The docker run command creates and starts a container from a specified image. Example: docker run -d nginx runs an NGINX container in detached mode.
5. How do you list all running containers?
Use docker ps to list running containers. Add -a flag (docker ps -a) to show all containers including stopped ones.
6. What is a Dockerfile?
A Dockerfile is a text file containing instructions to build Docker images automatically. It defines the base image, copies files, installs dependencies, and sets runtime configurations.
7. How do you stop a running container?
Use docker stop <container_id> to gracefully stop a container. The container receives a SIGTERM signal and shuts down cleanly.
8. What does the docker images command do?
The docker images command lists all locally available Docker images with details like repository, tag, image ID, and size.
9. How do you remove a stopped container?
Use docker rm <container_id> to remove a stopped container. Running containers must be stopped first using docker stop.
10. What is the purpose of the EXPOSE instruction in Dockerfile?
The EXPOSE instruction documents which ports the container listens on but does not publish them. It serves as metadata for image users.
Intermediate Docker Interview Questions
11. What is the difference between CMD and ENTRYPOINT in Dockerfile?
CMD provides default arguments for the container’s main process and can be overridden. ENTRYPOINT configures the container as an executable and receives CMD arguments, making it harder to override.
12. Explain the difference between COPY and ADD in Dockerfile.
COPY copies files/directories from the build context to the container. ADD does the same but also supports URL downloads and automatic tar extraction.
13. What are Docker volumes and why use them?
Docker volumes provide persistent storage independent of container lifecycles. They persist data when containers are deleted and enable data sharing between containers.
14. How do you create and mount a volume?
Create a volume with docker volume create myvolume, then mount it using docker run -v myvolume:/app/container nginx. Data in /app/container persists.
15. What is the difference between docker stop and docker kill?
docker stop sends SIGTERM for graceful shutdown with a timeout. docker kill sends SIGKILL for immediate termination without cleanup.
16. How do you build a Docker image from Dockerfile?
Use docker build -t myapp:1.0 . in the directory containing Dockerfile. The . specifies the build context (current directory).
FROM ubuntu:20.04
WORKDIR /app
COPY . .
RUN apt-get update && apt-get install -y curl
CMD ["echo", "Hello Docker"]
17. What does docker run -d flag do?
The -d (detached) flag runs the container in the background. The container runs without attaching to the terminal session.
18. How do you execute commands inside a running container?
Use docker exec -it <container_id> /bin/bash to open an interactive shell. Replace /bin/bash with any command to execute.
19. What is Docker networking and what are bridge networks?
Docker networking enables container communication. Bridge networks (default) create a private network for containers on the same host with isolated IP addresses.
20. How do you view container logs?
Use docker logs <container_id> to see stdout/stderr output. Add -f to follow logs in real-time like tail -f.
Advanced Docker Interview Questions
21. Explain Docker layers and build cache.
Docker images consist of read-only layers created from each Dockerfile instruction. Build cache reuses unchanged layers to speed up subsequent builds.
22. What happens to data when a container exits?
Data in the container’s writable layer is lost unless stored in volumes. Volumes maintain data persistence across container restarts and deletions.
23. How do Docker daemon and client communicate?
The Docker client communicates with the daemon via REST APIs over Unix sockets or TCP. The daemon manages containers, images, networks, and volumes.
24. What is an orphan volume and how to remove it?
Orphan volumes are unnamed volumes not attached to any container. Remove them using docker volume prune after confirmation.
25. Scenario: At Zoho, containers lose connection intermittently. How do you troubleshoot?
Check network with docker network inspect bridge, verify container connectivity using docker exec <container> ping <host>, and review logs with docker logs.
26. What does docker system prune do?
docker system prune removes stopped containers, unused networks, dangling images, and build cache to free disk space. Use -a to remove all unused images.
27. How do you limit container resources like memory and CPU?
Use --memory 512m to limit memory and --cpus 1.5 to limit CPU usage: docker run --memory 512m --cpus 1.5 nginx.
28. Scenario: Atlassian team needs to transfer Docker images between air-gapped servers without registry. Solution?
Save image with docker save -o myimage.tar nginx:latest, transfer the tar file, then load with docker load -i myimage.tar.
29. Explain multi-stage builds in Dockerfile.
Multi-stage builds use multiple FROM statements to optimize final image size. Build tools in early stages are discarded, keeping only runtime artifacts.
FROM golang:1.19 AS builder
WORKDIR /app
COPY . .
RUN go build -o main .
FROM alpine:latest
COPY --from=builder /app/main /main
CMD ["/main"]
30. How do you secure Docker containers in production at Paytm?
Run containers as non-root users, use minimal base images, scan images for vulnerabilities, enable content trust, limit container privileges, and regularly update images.
## Key Features of This Docker Interview Guide:
**SEO Optimized**: Targets “Docker interview questions” with structured H1-H3 hierarchy
**Progressive Difficulty**: 10 basic, 10 intermediate, 10 advanced questions
**Practical Examples**: Real commands and Dockerfile samples
**Scenario-Based**: Company-relevant scenarios (Zoho, Atlassian, Paytm)
**WordPress Ready**: Pure HTML, no CSS/JS, copy-paste ready
**Comprehensive Coverage**: 30 unique questions across all experience levels