Posted in

Top 30 Docker Interview Questions and Answers for All Experience Levels

Master Docker Concepts: Interview Questions from Basic to Advanced

Prepare for your next Docker interview with these 30 carefully curated questions and answers. Whether you’re a fresher, have 1-3 years of experience, or are a seasoned professional with 3-6 years, this guide covers conceptual, practical, and scenario-based questions in increasing difficulty.

Basic Docker Interview Questions (Freshers & 1-3 Years Experience)

1. What is Docker?

Docker is a platform that uses containerization technology to package applications and their dependencies into lightweight, portable containers that can run consistently across different environments.

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 and hosts containers), and Docker Registry (stores Docker images).

3. What is a Docker image?

A Docker image is a read-only template that contains the application code, runtime, libraries, and environment variables required to run an application inside a container.

4. What is a Docker container?

A Docker container is a runnable instance of a Docker image. It provides an isolated environment for applications to execute consistently across different systems.

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

A Docker image is the static blueprint, while a container is the dynamic, running instance created from that image. Multiple containers can be created from a single image.

6. What command is used to check the Docker version?

Use docker version to check both Docker Client and Docker Server versions.

7. How do you run a Docker container?

Use docker run <image_name> to create and start a new container from a specified image.

8. What command lists all running containers?

docker ps lists running containers. Use docker ps -a to see all containers including stopped ones.

9. How do you stop a running container?

Use docker stop <container_id> to gracefully stop a running container.

10. What is Docker Hub?

Docker Hub is a public registry service where users can store, share, and manage Docker images for public and private repositories.

Intermediate Docker Interview Questions (1-3 Years Experience)

11. What is a Dockerfile?

A Dockerfile is a text file containing a series of instructions to build a Docker image automatically. It defines the environment layer by layer.

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

CMD provides defaults for an executing container but can be overridden. ENTRYPOINT configures the container as an executable and cannot be overridden easily.

13. What is the difference between COPY and ADD in Dockerfile?

COPY copies files/directories to the container. ADD does the same but also supports URLs and automatic tar extraction.

14. What does EXPOSE do in a Dockerfile?

EXPOSE documents which ports the container listens on but does not actually publish them. Use -p flag in docker run to publish ports.

15. What is the difference between ‘docker run’ and ‘docker create’?

docker create creates a container but doesn’t start it. docker run creates and starts the container immediately.

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

Use docker build -t <image_name> . from the directory containing the Dockerfile.

17. What is a Docker volume?

Docker volumes provide persistent storage for containers. Data in volumes survives container deletion, unlike default container storage.

18. How do you create a volume and mount it to a container?

Create with docker volume create <volume_name>, then mount using docker run -v <volume_name>:<container_path> <image>.

19. What command removes all stopped containers?

docker container prune removes all stopped containers. Use docker system prune for broader cleanup.

20. Explain Docker networking basics.

Docker provides bridge (default), host, and overlay networks. Bridge networks allow container communication within the same host.

Advanced Docker Interview Questions (3-6 Years Experience)

21. What is Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications using a YAML file that specifies services, networks, and volumes.

22. How do you override the default command in Docker Compose?

Use the command directive in the docker-compose.yml file to override the CMD or ENTRYPOINT from the Dockerfile.

23. What are Docker layers?

Each instruction in a Dockerfile creates a layer. Docker caches these layers for faster rebuilds and image sharing between containers.

24. Scenario: At Zoho, your container keeps restarting. How do you troubleshoot?

Check logs with docker logs <container_id>, inspect status with docker inspect <container_id>, and verify restart policy.

25. What is an orphan volume and how do you remove it?

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

26. Explain multi-stage builds in Dockerfile.

Multi-stage builds use multiple FROM statements to separate build and runtime environments, resulting in smaller production images.

FROM node:14 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production

FROM node:14-alpine
COPY --from=builder /app/node_modules ./node_modules
COPY . .
CMD ["node", "app.js"]

27. Scenario: At Paytm, you need to transfer an image between machines without a registry. How?

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

28. What is the difference between ‘docker stop’ and ‘docker kill’?

docker stop sends SIGTERM (graceful shutdown). docker kill sends SIGKILL (immediate termination).

29. How do you limit container resources like CPU and memory?

Use --cpus=<value> for CPU and --memory=<value> for memory limits with docker run.

30. Scenario: At Atlassian, containers lose data on exit. How do you ensure persistence?

Mount volumes with -v /host/path:/container/path or named volumes to persist data beyond container lifecycle.

## Related Docker Interview Preparation Tips:

  • Practice building Dockerfiles for real applications
  • Experiment with Docker Compose for multi-container setups
  • Understand volume management for data persistence
  • Master Docker networking for container communication
  • Learn resource limiting for production deployments

Leave a Reply

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