20+ Docker Interview Questions
(ANSWERED) in 2020
1. What is Docker?
| Criteria | Docker | Virtual Machines |
| Use of OS | All containers share the host OS | Each VM runs on its own OS |
| Startup time | Very fast | Slow |
| Isolation | Process-level isolation | Full isolation |
| Security | Low | High |
We can define Docker as a containerization platform that combines all our applications in a package so that we have all the dependencies to run our applications in any environment. This means, our application will run seamlessly on any environment, and this makes it easy for having a product-ready application. What Docker does is wrap the software needed in a file system that has everything for running the code, providing the runtime and all the necessary libraries and system tools. Containerization technology like Docker will share the same operating system kernel with the machine, and due to this it is extremely fast. This means that we have to run Docker only at the beginning and after that, since our OS is already running, we will have a smooth and seamless process.
2. Explain Docker Container?
Answer: A container is the basic unit of software that holds the code and all its dependencies, in order to make the application run smoothly, quickly and reliably from one computing ecosystem to another. A Docker container may be created using a Docker image. It is an executable package of the software, which holds everything that is required to run an application, which are system tools, libraries, code, runtime, and settings.
3. What is the benefit of using a Docker over a Hypervisor?Answer: Though Docker and Hypervisor might do the same job overall, there are many differences between them in terms of how they work. Docker can be thought of as lightweight since it uses very fewer resources and also the host kernel rather than creating it like a Hypervisor.
4. Explain the components of Docker Architecture.
Answer: The components in Docker architecture are given below:
- Host: This component holds the Docker Daemon, Images, and Containers. While the Docker Daemon establishes a link with the Registry, the Docker Images act as metadata for the applications which are held in the Docker Containers.
- Client: The Docker Client component runs operations to set up communication with the Docker Host.
- Registry: This Docker Component is used to store the Docker Images. Docker Hub and Docker Cloud are public registries, which can be utilized by anyone.
5. What is a Docker image?
Answer: A Docker image helps in creating Docker containers. We can create the Docker image with the build command; due to this, it creates a container that starts when it begins to run. All the Docker images are stored in the Docker registry such as the public Docker registry. These have minimal amounts of layers within the image so that there is a minimum amount of data on the network.
6. What is a Docker Hub?
Answer: We can think of Docker Hub as a cloud registry that lets us link the code repositories, create the images, and test them. We can also store our pushed images, or we can link to the Docker Cloud, so that the images can be deployed to the host. We have a centralized container image discovery resource that can be used for the collaboration of our teams, automating the workflow and distribution, and changing management by creating the development pipeline.
7. Explain the Docker Registry in detail.
Answer: The place where all Docker Images are stored is known as the Docker Registry. The Docker Hub is a public registry which is the default storage for these images. Another public registry is Docker Cloud. The Docker Hub is the most significant public storehouse of the image containers, consistently maintained by a large number of developers, along with many individual contributors.
8. Briefly explain the Docker Container lifestyle.
Answer: The lifecycle of a Docker Container is:
- Creation of the container
- Running the container
- Pausing the container
- Unpausing the container
- Starting the container
- Stopping the container
- Restarting the container
- Killing the container
- Destroying the container
9. Name some important Docker commands
Answer: Below are some important Docker commands:
- build: to build an image file for Docker
- create: for creation of a new container
- kill: to kill a container
- dockerd: for launching Docker daemon
- commit: for creating a new image from the container changes
10. What are Namespaces in Docker.
Answer: Docker Namespaces is a technology providing isolated workspaces knows as a container. Once a container is started, a set of namespaces is created for the said container. These namespaces provide a layer of seclusion for these containers as each container functions in a distinct namespace, with its access limited to the mentioned namespace.
11. What is Docker Swarm?
Answer: Docker Swarm is a native tool used for clustering and scheduling Docker containers. Using Docker Swarm, developers and IT supervisors can easily establish and manage a bunch of nodes in Docker or a solitary Virtual System (VS).
12. How to identify the status of a Docker Container?
Answer: To identify the status of a Docker container, one should run the command
“docker ps-a”
This command will furnish the list of all available Docker containers with the respective status on the host. From the list one can easily make out the intended container to check its status.
13. What are the Docker Image and Docker Run Command?
Answer: A Docker Image is a group of files and an amalgamation of parameters which allow the creation of instances that run in distinct containers as isolated processes. An image is basically built using the instructions for a complete and executable version of an application, which relies on the host OS kernel. The Docker run command can be used to create the instance called container which can be run using the Docker image. When the Docker user runs an image, it becomes one or multiple instances of that container.
14. Explain the use of Docker File.
Answer: Docker file contains a bunch of instructions that are passed on Docker to make possible the build process of images, which can automatically read these instructions. It can also be termed as a text document containing all the possible commands that a user may call on the command line for assembly of an image.
15. Which networks all available by default in Docker?
Answer: The default networks available in Docker are:
- bridge: Default network which the containers connect to if the network is not specified otherwise
- none: Connects to a container-specific network stack lacking a network interface
- host: Connects to the host’s network stack
16. List the steps in a deploy process for Dockerized Apps stored In A Git Repo.
Answer: While the deploy process changes with your production environment, a basic deploy process will have the following:
- Build an application through Docker Build located in the code directory
- Perform the test of an image
- Push the new image to registry docker
- Notify the remote application server to get hold of the image from the registry and run it
- Port swapping in HTTP proxy
- Stop the older container
17. Explain how Docker is different from other container technologies.
Answer: Docker is one of the latest container technologies and has emerged as one of the most popular. Built-in the era of cloud, Docker comes with a whole lot of new features that were missing in older container technologies. One of the finest features of Docker is that it can run on any infrastructure, be it your home machine or the Cloud.
Through Docker, more applications can now run on the old servers, and it also allows the process to package and ship programs. Docker also has a Container Hub that acts as a repository for containers, which are easy to download and use. Moreover, these containers can also be shared by your applications. It is also very well documented, which makes it better than other container technologies.
18. If you were to exit the Docker Container, will you lose your data?
Answer: When a Docker Container is exited, no data loss occurs as all the data is written to the disk by the application for the sole purpose of preservation. This process is consistently repeated until and unless the container is unequivocally deleted. Moreover, the file system for the Docker container persists even after the Docker container is halted.
19. How is Docker monitored in production?
Answer: To monitor Docker in production, tools such as Docker stats and Docker events are available. Through these tools, one can get reports on important statistics. Once Docker stats is called with a container ID, it returns the CPU and memory usage of the container. It is similar to the top command in Linux. On the other hand, Docker Events are commands to see a list of activities in process in Docker Daemon. Some of these events are attached, commit, rename, destroy, die and more. One also has the option to filter the events they are interested in.
20. What is the difference between the `COPY` and `ADD` commands in a Docker file?
Answer: 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 /.
21. Explain CMD and ENTRYPOINT in a Dockerfile?
Answer: In a Dockerfile, both CMD and ENTRYPOINT instructions define which command will be executed while running a container. For their cooperation, there are some rules, such as:
- The Dockerfile should specify at least one command from CMD or ENTRYPOINT
- While using the container as an executable, ENTRYPOINT needs to be defined
- When running the container with an alternative argument, CMD will be overridden
22. Explain the process to run an application inside a Linux Container
using Docker
Answer: Below are the steps on how to run an application inside the Linux Container using Docker
- Install and run Docker
- Fetch Fedora 21 (Linux based OS) base image from the Docker hub
- Load your application in the Docker base image
- Run container using your new image in interactive mode
- Check the containers in the system
- Start or stop Docker container
- Go inside a Docker container
- Remove container or image
What are the various states that a Docker container can be in at any given point in time?
Answer: There are four states that a Docker container can be in, at any given point in time. Those states are as given as follows:
- Running
- Paused
- Restarting
- Exited
24.What are the most common instructions in Dockerfile?
Answer: 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.

Post a Comment