DEV Community

Cover image for Top 40 Docker interview questions (with answers)
Erin Schaffer for Educative

Posted on • Originally published at educative.io

Top 40 Docker interview questions (with answers)

Docker is a popular open-source software platform that simplifies the process of creating, managing, running, and distributing applications. It uses containers to package applications along with their dependencies. Docker dominates the market. Most of the top cloud and IT companies have adopted Docker to streamline their application development workflows. The demand for applicants with Docker experience is high.

Cracking your Docker interview is the key to landing one of these highly coveted roles. We’ve gathered the top 40 Docker interview questions to help you prepare for your Docker interview. This Docker tutorial includes both questions and answers. Let’s get started!

We'll cover:

Docker interview questions and answers

1. What are Docker containers?

Docker containers create an abstraction at the application layer and package applications together with all of their dependencies. This allows us to deploy applications quickly and reliably. Containers don’t require us to install a different operating system. Instead, they use the underlying system’s CPU and memory to perform tasks. This means that any containerized application can run on any platform regardless of the underlying operating system. We can also think of containers as runtime instances of Docker images.

2. What is a DockerFile?

A Dockerfile is a text file that contains all of the commands that we need to run to build a Docker image. Docker uses the instructions in the Dockerfile to automatically build images. We can use docker build to create automated builds that execute multiple command-line instructions in sequential order.

3. How do you create a Docker container from a Docker image?

To create a container from an image, we pull out the image that we want from the Docker repository and create a container. We can use the following command:

$ docker run -it -d <image_name>
Enter fullscreen mode Exit fullscreen mode

4. Can you use JSON instead of YAML for Docker Compose?

Yes, we can use a JSON file instead of a YAML file for the Docker Compose file. To use JSON, we need to specify the filename like this:

$ docker-compose -f docker-compose.json up
Enter fullscreen mode Exit fullscreen mode

5. What is Docker Swarm?

Docker Swarm is a container orchestration tool that allows us to manage multiple containers across different host machines. With Swarm, we can turn multiple Docker hosts into a single host for easy monitoring and management.

6. If you want to use a base image and make modifications to it, how do you do that?

We can pull an image from Docker Hub onto our local system using the following Docker command:

$ docker pull <image_name>
Enter fullscreen mode Exit fullscreen mode

7. How do you start, stop, and kill containers?

To start a Docker container, use the following command:

$ docker start <container_id>
Enter fullscreen mode Exit fullscreen mode

To stop a Docker container, use the following command:

$ docker stop <container_id>
Enter fullscreen mode Exit fullscreen mode

To kill a Docker container, use the following command:

$ docker kill <container_id>
Enter fullscreen mode Exit fullscreen mode

8. What platforms does Docker run on?

Docker runs on the following Linux distributions:

  • CentOS 6+
  • Gentoo
  • ArchLinux
  • CRUX 3.0+
  • openSUSE 12.3+
  • RHEL 6.5+
  • Fedora 19/20+
  • Ubuntu 12.04, 13.04

Docker can also be used in production with these cloud services:

  • Microsoft Azure
  • Google Compute Engine
  • Amazon AWS EC2
  • Amazon AWS ECS
  • Rackspace

Tip: We always recommend engaging in some company research prior to your interview. To prepare for this particular question, find out how to company uses Docker and include the platform they use in your answer.

9. Explain the Docker components.

The three architectural components include Docker Client, Host, and Registry.

  • Docker Client: This component executes build and run operations to communicate with the Docker Host.

  • Docker Host: This component holds the Docker Daemon, Docker images, and Docker containers. The daemon sets up a connection to the Docker Registry.

  • Docker Registry: This component stores Docker images. It can be a public registry, such as Docker Hub or Docker Cloud, or a private registry.

10. What's the difference between virtualization and containerization?

Virtualization

Virtualization helps us run and host multiple operating systems on a single physical server. In virtualization, hypervisors give a virtual machine to the guest operating system. The VMs form an abstraction of the hardware layer so each VM on the host can act as a physical machine.

Containerization

Containerization provides us with an isolated environment for running our applications. We can deploy multiple applications using the same operating system on a single server or VM. Containers form an abstraction of the application layer, so each container represents a different application.

11. What is the functionality of a hypervisor?

A hypervisor, or virtual machine monitor, is software that helps us create and run virtual machines. It enables us to use a single host computer to support multiple guest virtual machines. It does this by dividing the system resources of the host and allocating them to the installed guest environments. Multiple operating systems can be installed on a single host operating system. There are two kinds of hypervisors:

  • Native: Native hypervisors, or bare-metal hypervisors, run directly on the underlying host system. It gives us direct access to the hardware of the host system and doesn’t require a base server operating system.

  • Hosted: Hosted hypervisors use the underlying host operating system.

12. How do you build a Dockerfile?

In order to create an image with our outlined specifications, we need to build a Dockerfile. To build a Dockerfile, we can use the docker build command:

$ docker build <path to dockerfile>
Enter fullscreen mode Exit fullscreen mode

13. What command do you use to push a new image to the Docker Registry?

To push a new image to the Docker Registry, we can use the docker push command:

$ docker push myorg/img
Enter fullscreen mode Exit fullscreen mode

14. What is Docker Engine?

Docker Engine is an open-source containerization technology that we can use to build and containerize our applications. Docker Engine is supported by the following components:

  • Docker Engine REST API
  • Docker Command-Line Interface (CLI)
  • Docker Daemon

15. How do you access a running container?

To access a running container, we can use the following command:

$ docker exec -it <container_id> bash
Enter fullscreen mode Exit fullscreen mode

16. How do you list all the running containers?

To list all of the running containers, we can use the following command:

$ docker ps
Enter fullscreen mode Exit fullscreen mode

17. Describe the lifecycle of a Docker container.

Docker containers go through the following stages:

  • Create a container
  • Run the container
  • Pause the container (optional)
  • Un-pause the container (optional)
  • Start the container
  • Stop the container
  • Restart the container
  • Kill the container
  • Destroy the container

18. What are Docker object labels?

Docker object labels are key-value pairs that are stored as strings. They enable us to add metadata to Docker objects such as containers, networks, local daemons, images, Swarm nodes, and services.

19. How do you ensure that container 1 runs before container 2 while using Docker Compose?

Docker Compose doesn’t wait for containers to be ready before moving forward with the next container. In order to control our order of execution, we can use the "depends on" condition, depends_on. Here’s an example of it being used in a docker-compose.yml file:

version: "2.4"
services:
 backend:
   build: .
   depends_on:
     - db
 db:
   image: postgres
Enter fullscreen mode Exit fullscreen mode

The docker-compose up command will start and run the services in the dependency order that we specify.

20. What does the docker create command do?

The docker create command creates a writable container layer over a specified image and prepares that image for running the specified command.

20 more interview questions to explore

  • 21. Explain Docker architecture.
  • 22. What's the difference between CMD and ENTRYPOINT?
  • 23. What is the purpose of the volume parameter in a Docker run command?
  • 24. Is it a good practice to run stateful applications on Docker?
  • 25. What are Docker Namespaces?
  • 26. Explain the implementation method of continuous integration and continuous deployment in Docker.
  • 27. What is the process for stopping and restarting a Docker container?
  • 28. How do you give your Docker image an image name?
  • 29. What does the docker service command do?
  • 30. Can you lose data when the container exits?
  • 31. How do Jenkins and Docker work together?
  • 32. How far do Docker containers scale?
  • 33. Describe the differences between daemon logging and container logging.
  • 34. Explain the purposes of up, run, and start commands of Docker compose.
  • 35. Where are Docker volumes stored?
  • 36. Explain the difference between Docker image and layer.
  • 37. Can a paused container be removed from Docker?
  • 38. How do you use the docker save and docker load commands?
  • 39. What is the default Docker network driver? How can you change it when running a Docker image?
  • 40. What does the docker system prune command do?

Next steps

Congrats! You made it to the end. Preparing for your Docker interview will take time, so be patient with the process. Be prepared to spend a lot of time studying and preparing. There’s still more to learn about Docker. Some recommended topics to cover next include:

  • Docker with common development profiles
  • Docker security
  • Private registries

To get started learning these concepts and a lot more, check out Educative's learning path DevOps for Developers. In this curated learning path, you’ll get hands-on practice with Docker and Kubernetes. By the end, you’ll have cutting-edge stills and hands-on experience so you can excel in your DevOps role.

Happy learning!

Continue reading about interview prep

Top comments (6)

Collapse
 
andreidascalu profile image
Andrei Dascalu

1 - slightly wrong. You're not using just system resources. A container uses the whole of the host's OS kernel. You can't run any container on any OS regardless. For example, to run a docker container in Windows you need an extra abstraction, by default a HyperV VM or the kernel provided by the WSL2 (which is a bit closer to the proper OS). For example on Windows if you have HyperV & WSL2 disabled, Docker will complain it can't run.
3 - ok, but you might better ask "what's the relationship between image and container" ?
4 - it's a bad interview question format because it's a leading question. Somehow who doesn't know still has a 50% chance of getting it right since it's a yes/no question. You should ask what are the accepted formats for a compose file.
8 - pointless question. You're asking about platforms so the plain answer is Linux/Unix , Windows, Mac. The listing of cloud providers is pointless, Docker runs on the OS installed on their VMs, nothing to do with the cloud provider itself. The listing of distros is also pointless ... you're asking if the candidate knows all the Linux distros? You missed Mandriva ... is that bad?
17 - create container? a container is a running image. I find the "create" bit somewhat meaningless since it's part of running it.
19 - starts or runs? depends_on ensures the container will start but might not achieve a running state before the next one. A healthcheck improves the chances of that.

Collapse
 
danbmky profile image
Dan Bamikiya • Edited

If you're going to correct a post someone puts their hardwork in making for others to learn and strengthen their understanding, you might as well correct it respectfully.

If you had perfect knowledge of this topic why didn't you write the post yourself??

Better still you might as well have answered the 20 more questions with no answers.

Collapse
 
andreidascalu profile image
Andrei Dascalu

You don't have to have perfect knowledge to point out glaring mistakes. It's like seeing someone trying to nail something using a shoe instead of a hammer who says only someone who has been a master carpenter for 20 years is allowed to point out that a hammer is a better tool.
Hard work is a relative matter. For example, the fact that Docker uses the host kernel is in the documentation. It's better to provide the questions as-is and let people learn by doing the research (the questions themselves are good) rather than provide wrong/misleading answers.

Thread Thread
 
danbmky profile image
Dan Bamikiya

Seems like you didn't read the part where I said you should correct respectfully

You're contradicting yourself saying "the questions themselves are good" when you literally called them "wrong", "bad interview question", "pointless".

If you feel a post is "wrong", "bad" or "pointless", there's nothing bad, its your view. But you should atleast correct respectfully if you're going to correct.

Thread Thread
 
andreidascalu profile image
Andrei Dascalu

There's a difference between question and answer. One is pointless and another could be improved by asking it differently. Some of the answers are wrong, which is what I specifically said. The questions are ok as interview questions.

Collapse
 
tsadarsh profile image
Adarsh TS • Edited

Thanks for sharing. I was able to strengthen my understanding in Docker more.