Docker Interview Questions and Answers

Docker

25 Important Docker Interview Questions and Answers

Following are frequently asked Docker job interview questions for fresher as well as experienced DevOps engineers.

Q1. What is Docker?


Docker is an open-source lightweight containerization technology. It has gained widespread popularity in the cloud and application packaging world. It allows you to automate the deployment of applications in lightweight and portable containers. A Docker Container is a form of encapsulation to the application which holds all the dependencies which share the kernel with other containers in the duration of running the isolated processes on the host operating system. A Docker container can be created by creating a Docker image. These Docker images can be run after that using Docker commands. Docker containers are the instances of the Docker images at the runtime. Docker images can be stored in any public hosts or private hosts like Docker hub. Docker Image is a set of files which can be run in an isolated process.

Q2. What are the important features of Docker?


Here are the essential features of Docker:

Easy Modeling
Version control
Placement/Affinity
Application Agility
Developer Productivity
Operational Efficiencies

Q3. What is Docker image?

The Docker image help to create Docker containers. You can create the Docker image with the build command. Due to this, it creates a container that starts when it begins to run. Every docker images are stored in the Docker registry.

Q4. What is Docker Engine?

Docker daemon or Docker engine represents the server. The docker daemon and the clients should be run on the same or remote host, which can communicate through command-line client binary and full RESTful API.

Q5. What is a Docker Registry?


A Docker Registry is a place where all the Docker Images will be stored and Docker Cloud and Docker Hub are the public registries where these images can be hosted upon. The Docker hub is the default storage for the Docker Images. An own registry can also be set up as per the requirement. Docker Data Center (DDC) can also be used which includes DTR (Docker Trusted Registry). Docker store will provide the feature of buying and selling the Docker images.


Q6. Explain Registries

There are two types of registry is

  1  Public Registry
  2  Private Registry

Docker's public registry is called Docker hub, which allows you to store images privately. In Docker hub, you can store millions of images.

Q7. What is the lifecycle of Docker Container?


Answer:
This is the most popular Docker Interview Questions asked in an interview. The life cycle of the Docker container is as below:

    Create a container.
    Run the Docker container.
    Pause the Container.
    Unpause the Container.
    Start the Container.
    Stop the Container.
    Restart the Container.
    Kill the Container.
    Destroy the Container.

Q8. What is the difference between the COPY and ADD commands in a Dockerfile?


Although ADD and COPY are functionally similar, generally speaking, COPY is preferred.

That’s because it’s more transparent than ADD. COPY only supports the basic copying of local files into the container, while ADD has some features (like local-only tar extraction and remote URL support) that are not immediately obvious. Consequently, the best use for ADD is local tar file auto-extraction into the image, as in ADD rootfs.tar.xz /.

Q9. Explain Docker Swarm?


Docker Swarm is native gathering for docker which helps you to a group of Docker hosts into a single and virtual docker host. It offers the standard docker application program interface.

Q10. What the states of Docker container?

Important states of Docker container are:

    Running
    Paused
    Restarting
    Exited

Q11. What is a Dockerfile?

A great example of some of the more basic interview questions on Docker – and not a difficult one at that!

Remember the comparison I made between Docker and a carrier boat? Well, somebody has to give the boat instructions on what to carry, where to carry it and so on. A Dockerfile is exactly such a set of instructions. Developers provided Docker with such instructions so that the program could do the job correctly, with those specific parameters in mind.

Q12. What are the most common instructions in Dockerfile?

Some of the common instructions in Dockerfile are as follows:

## FROM: We use FROM to set the base image for subsequent instructions. In every valid Dockerfile, FROM is the first instruction.
## LABEL: We use LABEL to organize our images as per project, module, licensing etc. We can also use LABEL to help in automation.In LABEL we specify a key value pair that can be later used for programmatically handling the Dockerfile.
## RUN: We use RUN command to execute any instructions in a new layer on top of the current image. With each RUN command we add something on top of the image and use it in subsequent steps in Dockerfile.
## CMD: We use CMD command to provide default values of an executing container. In a Dockerfile, if we include multiple CMD commands, then only the last instruction is used.
   

Q13. What type of applications - Stateless or Stateful are more suitable for Docker Container?  
 
   
It is preferable to create Stateless application for Docker Container. We can create a container out of our application and take out the configurable state parameters from application. Now we can run same container in Production as well as QA environments with different parameters. This helps in reusing the same Image in different scenarios. Also a stateless application is much easier to scale with Docker Containers than a stateful application.

Q14. How will you monitor Docker in production?


Docker provides tools like docker stats and docker events to monitor Docker in production. We can get reports on important statistics with these commands.

    Docker stats: When we call docker stats with a container id, we get the CPU, memory usage etc of a container. It is similar to top command in Linux.
    Docker events: Docker events are a command to see the stream of activities that are going on in Docker daemon.

Some of the common Docker events are: attach, commit, die, detach, rename, destroy etc. We can also use various options to limit or filter the events that we are interested in.

Q15. What are the three components of Docker Architecture


    Client
    Docker-Host
    Registry

The client is the component that issues “run” and “build” commands to the host. The host is where all of the containers and images are created. They are then sent to the registry, for execution.

Q16. Can you use any other files for composing instead of the default YAML?


Yes, yes you can. Truth be told, the more popular version to use than YAML is the good-old JSON. And there are no clashings or any other types of unwanted occurrences – you can use it without a problem.

Q17.  What are the main factors that dictate the number of containers you can run?

There isn’t a clearly-defined limit of containers that you run with Docker. However, that being said, the limitations come in when we start talking about hardware.

Two factors might limit the number of containers that you can run – the size of your app and your CPU strength. If your application isn’t ginormous and you have a never-ending supply of CPU power, you could probably run a huge amount of Docker container simultaneously.

Q18.  How is Docker different from Hypervisor?

Again, one of the Docker interview questions that require you to have some more extensive knowledge of development tools other than Docker. Answering this question thoroughly, you show competence in the general field of development, and not only things relating to Docker (which is a good thing!).

It all boils down to one, simple thing – Hypervisor requires you to have extensive hardware to function properly, while Docker runs on the actual operating system. This allows Docker to be exceptionally fast and perform tasks in a fluid manner – something that Hypervisor tends to lack.

Q19. How does communication happen between Docker client and Docker Daemon?

You can communicate between Docker client and Docker Daemon with the combination of Rest API, socket.IO, and TCP.

Q20. Does Docker offer support for IPV6?


Yes, Docker provides support IPv6. IPv6 networking is supported only on Docker daemons runs on Linux hosts. However, if you want to enable IPv6 support in the Docker daemon, you need to modify /etc/docker/daemon.json and set the ipv6 key to true.

Q21. What are Docker Namespaces?

The Namespace in Docker is a technique which offers isolated workspaces called the Container. Namespaces also offer a layer of isolation for the Docker containers.
   
Q22. What are the different functionalities and applications of using Docker?

Answer:
The different functionalities and applications of using and implementing Docker are as below:

    It simplifies the configuration and provides ease at infrastructure level configuration.
    It manages the code pipeline easily which provides consistent environment and stability in the application.
    It enables the isolation of the application.
    It improves the productivity of the developer by allowing the developer to solely concentrate on business logic.
    It enables a lot of debugging capabilities that provides extreme useful functionalities to implement.
    It enables rapid deployment in the form of virtualization at the operating system level.
    It reduces the utilization of multiple servers in the form of containerization.
    
Q23. Will you lose all of your work if you accidentally exit a container?

Similar Docker interview questions might aim to throw you off balance and make you second-guess your knowledge. However, don’t be discouraged by your answer!

No, you won’t lose any information, data and other parameters if you accidentally exit the Docker container. The only way to lose your progress would be to issue a specific command to delete the container – exiting it won’t do the files within any harm.   
   
Q24. What is the purpose of Docker_Host?


It contains container, images, and Docker daemon. It offers a complete environment to execute and run your application.

Q25. What are a different kind of volume mount types available in Docker?


Bind mounts- It can be stored anywhere on the host system