All interview guides

Docker Interview Questions and Answers

24 questions that come up in Docker technical interviews, each with the answer and an explanation of why it is right.

Test yourself — 90 question bank

1. What is a Docker volume?

Intermediate

Answer: A persistent data storage mechanism

Docker volumes are the preferred mechanism for persisting data generated and used by Docker containers. They are managed by Docker and exist outside the container lifecycle.

2. What is Docker primarily used for?

Beginner

Answer: Containerization

Docker is a platform for developing, shipping, and running applications inside lightweight, portable containers that package code and dependencies together.

3. What is Docker Swarm?

Advanced

Answer: Native clustering and orchestration for Docker

Docker Swarm is Docker native clustering and orchestration solution that turns multiple Docker hosts into a single virtual host.

4. What is the difference between Docker Swarm and Kubernetes?

Advanced

Answer: Swarm is simpler, Kubernetes is more feature-rich

Docker Swarm is easier to set up and use but less feature-rich. Kubernetes is more complex but offers more advanced orchestration, scaling, and ecosystem.

5. What is the difference between a volume and a bind mount?

Intermediate

Answer: Volumes are managed by Docker, bind mounts link to host filesystem

Volumes are stored in Docker-managed space and are isolated from host. Bind mounts directly map host filesystem paths into containers.

6. What is a Docker service in Swarm mode?

Advanced

Answer: Definition of tasks to run on worker nodes

A service is the definition of tasks to execute on manager or worker nodes. It defines the container image, replicas, ports, and other configurations.

7. What is Docker Compose used for?

Intermediate

Answer: Defining and running multi-container applications

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

8. What is a Docker image?

Beginner

Answer: A read-only template for creating containers

A Docker image is a lightweight, standalone, immutable file that contains everything needed to run an application, including code, runtime, libraries, and dependencies.

9. What is the purpose of docker secret?

Advanced

Answer: To securely store and manage sensitive data

Docker secrets securely store and manage sensitive data like passwords, tokens, and keys in Swarm mode. Secrets are encrypted in transit and at rest.

10. How do you initialize a Docker Swarm?

Advanced

Answer: docker swarm init

`docker swarm init` initializes a swarm, making the current node a manager. It returns a join token for adding worker nodes.

11. Which file defines multi-container Docker applications?

Beginner

Answer: docker-compose.yml

`docker-compose.yml` is a YAML file that defines services, networks, and volumes for multi-container Docker applications.

12. What is a Docker stack?

Advanced

Answer: A group of interrelated services in Swarm

A stack is a group of interrelated services that share dependencies and can be orchestrated together in Swarm mode. Defined using docker-compose.yml v3+.

13. What is a multi-stage build in Docker?

Intermediate

Answer: Using multiple FROM statements to reduce final image size

Multi-stage builds use multiple FROM statements in a Dockerfile. This allows building in one stage and copying only necessary artifacts to the final stage, reducing image size.

14. Which network driver is the default for containers on the same host?

Intermediate

Answer: bridge

Bridge is the default network driver. It creates a private internal network on the host where containers can communicate.

15. What does "docker run" do?

Beginner

Answer: Creates and starts a new container from an image

`docker run` creates a new container from a specified image and starts it. It combines `docker create` and `docker start`.

16. What is the purpose of Docker Content Trust (DCT)?

Advanced

Answer: To verify integrity and publisher of images

Docker Content Trust uses digital signatures to verify the integrity and publisher of Docker images, preventing tampering and ensuring authenticity.

17. Which command displays Docker version information?

Beginner

Answer: All of the above

All three commands work: `docker --version`, `docker version`, and `docker -v`. The `docker version` command provides more detailed information.

18. What is the purpose of docker inspect command?

Intermediate

Answer: To return detailed information about Docker objects

`docker inspect` returns low-level information about Docker objects (containers, images, volumes, networks) in JSON format.

19. What is the purpose of docker config in Swarm?

Advanced

Answer: To store non-sensitive configuration data

Docker configs allow storing non-sensitive configuration data outside container images in Swarm mode. Similar to secrets but for non-sensitive data.

20. Which command stops a running container?

Beginner

Answer: docker stop

`docker stop` gracefully stops a container by sending SIGTERM, then SIGKILL after a grace period. `docker kill` sends SIGKILL immediately.

21. What is the ingress network in Docker Swarm?

Advanced

Answer: Overlay network for service discovery and load balancing

The ingress network is a special overlay network that provides load balancing for swarm services. All nodes participate in routing mesh.

22. How do you pass environment variables to a container?

Intermediate

Answer: All of the above

Environment variables can be passed using -e flag, --env-file for multiple variables from a file, or environment section in docker-compose.yml.

23. What is the routing mesh in Docker Swarm?

Advanced

Answer: Load balancing feature that routes requests to available tasks

Routing mesh enables all swarm nodes to accept connections on published ports, automatically routing to available service tasks.

24. How do you constrain service placement in Swarm?

Advanced

Answer: All of the above

Placement constraints control which nodes run service tasks. Can use node attributes (role, labels, hostname) with constraint syntax in service definitions.

Ready to test yourself?

The full Docker bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.

Take the Docker quiz