Posted in

Top 30 Docker Interview Questions and Answers for All Experience Levels

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, ideal for freshers, candidates with 1-3 years experience, and professionals with 3-6 years in Docker containerization.

Basic Docker Interview Questions (1-10)

1. What is Docker and what are its main components?

Docker is a platform for developing, shipping, and running applications in containers. It has three main components: Docker Client (performs build and run operations), Docker Host (contains the daemon that hosts containers and images), and Docker Registry (stores Docker images like Docker Hub).[3][1]

2. What is the difference between a Docker image and a container?

A Docker image is a read-only template containing application code, libraries, and dependencies. A container is a runnable instance of an image, providing isolated execution environment.[1][5]

3. How do you check the version of Docker client and server?

Use the command docker version to display both client and server versions. For server version only, use docker version --format '{{.Server.Version}}'

4. What command lists all Docker containers including stopped ones?

The command docker ps -a lists the status of all containers, both running and stopped.[3][5]

5. What command shows only running Docker containers?

Use docker ps to view all currently running containers.[3][4]

6. How do you start a stopped Docker container?

Run docker start <container_id> to start a stopped container by its ID or name.[4]

7. What is the difference between docker stop and docker kill?

docker stop sends a SIGTERM signal allowing graceful shutdown. docker kill sends SIGKILL for immediate termination.[4][2]

8. How do you run a Docker container in detached mode?

Use docker run -d <image_name>. The -d flag runs the container in detached (background) mode.[4]

9. What does the docker run command do?

docker run creates and starts a container from a specified image. Use docker create to only create without starting.[2][3]

10. When do you lose data stored in a Docker container?

Data persists in a container until the container is explicitly deleted using docker rm. Stopping or restarting doesn't delete data.[3][5]

Intermediate Docker Interview Questions (11-20)

11. What is a Dockerfile?

A Dockerfile is a text script containing instructions to build a Docker image layer by layer automatically.[1]

12. Explain the difference between COPY and ADD in Dockerfile.

COPY copies files from source to destination. ADD does the same but also supports URL downloads and automatic tar extraction.[2]

13. What is the difference between CMD and ENTRYPOINT in Dockerfile?

CMD provides default arguments for the container's main process (can be overridden). ENTRYPOINT configures the main executable and cannot be easily overridden.[2]

14. What does EXPOSE do in a Dockerfile?

EXPOSE documents which ports the container listens on but doesn't publish them. Use -p flag during docker run to publish ports.[1][2]

15. What is the difference between "expose" and "publish" in Docker?

EXPOSE in Dockerfile documents ports. PUBLISH (-p flag) makes container ports accessible from the host.[2]

16. How do you build a Docker image from a Dockerfile?

Use docker build -t <image_name> .. The . specifies the build context (current directory containing Dockerfile).[1]

17. What command removes all stopped containers and unused Docker objects?

docker system prune removes stopped containers, unused networks, build caches, and dangling images.[3]

18. What are Docker volumes and why use them?

Docker volumes provide persistent storage independent of container lifecycle. Data in volumes survives container deletion.[1]

19. How do you access a running container's shell?

Use docker exec -it <container_id> /bin/bash. The -it flags enable interactive terminal access.[6]

20. What is a Docker registry and what's the difference from a repository?

Docker registry stores images (like Docker Hub). A repository is a collection of related images with different tags within a registry.[2][5]

Advanced Docker Interview Questions (21-30)

21. What is Docker Compose and when would you use it?

Docker Compose manages multi-container applications using YAML files. Use it for defining services, networks, and volumes for complex apps.[6]

22. How do you control service startup order in Docker Compose?

Use depends_on in docker-compose.yml to specify startup sequence between services.[2]

23. What is a Docker image build cache?

Build cache stores intermediate layers from previous builds to speed up subsequent image builds by reusing unchanged layers.[2]

24. How do you transfer a Docker image between machines without a registry?

Save image to tar file with docker save -o image.tar <image>, transfer file, then load with docker load -i image.tar

25. What are orphan volumes in Docker and how to remove them?

Orphan volumes are volumes not referenced by any container. Remove with docker volume prune

26. Scenario: At Zoho, your container exceeds memory limits. How do you set memory limits?

Use docker run --memory="512m" <image> to limit container to 512MB RAM. Docker doesn't reserve memory, it only limits usage.[2]

27. Scenario: At Paytm, you need environment-specific deployments. How to handle with Docker?

Create environment-specific docker-compose files (docker-compose.prod.yml) with different volume bindings, ports, and restart policies.[4][6]

28. What is the ONBUILD instruction in Dockerfile?

ONBUILD adds instructions executed when the image is used as base for another image build.[2]

29. Scenario: At Salesforce, containers fail to communicate. How to link them?

Use --link flag (legacy) or create custom networks with docker network create and run containers on same network.[2]

30. How do you secure Docker containers in production at Atlassian?

Steps include: use minimal base images (distroless), run as non-root user, scan images for vulnerabilities, limit container privileges, and enable security scanning.[7]

Master Docker for Your Next Interview

Practice these Docker interview questions covering basic commands, Dockerfile optimization, volumes, networking, and production scenarios. Build hands-on experience with Dockerfiles, Compose files, and container orchestration to demonstrate expertise across all levels.

Leave a Reply

Your email address will not be published. Required fields are marked *