Top 50 Interview Questions on Containerization Tool & Docker

1. What is Docker?

A Docker is defined as the platform for containerizing the applications to isolate it from one another so as to make sure high availability and more efficiency regardless of the environments such as Development, Testing or Production. All the application related dependencies such as libraries, jar files, server related configurations, infrastructure-related elements will be packaged and formed as containers called containerized applications which do not need any dependency and work independently. It ensures the application to be run irrespective of the external factors. Containers in Docker have support from Docker Engine and Host OS to support all the operational or infrastructural related dependencies.

2. Explain the Architecture of Docker Explain and its components?

This is the common Docker Interview Questions asked in an interview. Docker works on client-server architecture. The Docker client communicates with the Docker Daemon. The Docker client and Daemon can run on an equivalent system. A Docket client also can be connected to a foreign Docker Daemon. The different sorts of Docker components during a Docker architecture are–

  • Docker Client: This performs Docker build pull and run operations to determine communication with the Docker Host. To call the queries to be run the Docker command uses Docker API.
  • Docker Host: This component contains Containers, Docker Daemon and its images. The images will be the kind of metadata for the applications which are containerized in the containers. The Docker Daemon establishes a connection with Registry.
  • Registry: This component is going to be storing the Docker images. The public registries are Docker Hub and Docker Cloud which can be used by anyone.

3. What is Docker Container?

A Docker Container may be a sort of encapsulation to the appliance which holds all the dependencies which share the kernel with other containers within 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 are often run then using Docker commands.  At runtime the docker containers are the instances of the Docker images. Docker images are often stored in any public hosts or private hosts like Docker hub. Docker Image may be a set of files which may be run in an isolated process.

4. What are Docker Image and Docker Hub?

The Docker Image is a set of files and a combination of parameters which will allow creating the instances to run in separate containers as an isolated process. The Docker hub may be a quiet repository to the pictures where these images are often stored and this access is public. The Docker run command often wants to create the instance called container which may be run using the Docker image. Docker hub is the largest public repository of the image containers which is being maintained by the community of developers and individual contributors.

5. What are the various functionalities and applications of using Docker?

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

  • It simplifies the configuration and provides ease at infrastructure level configuration.
  • It manages the code pipeline easily which provides consistent environment and stability within the application.
  • It enables the isolation of the application.
  • It improves the productivity of the developer by allowing the developer to solely consider business logic.
  • It enables a lot of debugging capabilities that provides extremely 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.

6. What is a Docker Registry?

A Docker Registry may be a place where all the Docker Images are going to be stored and Docker Cloud and Docker Hub are the general public registries where these images are often hosted upon. For the Docker Images the default storage is Docker hub. An own registry also can be found out as per the need . Docker Data Center (DDC) also can be used which incorporates DTR (Docker Trusted Registry). Docker stores will provide the feature of buying and selling the Docker images.

7. What is the lifecycle of Docker Container?

This is the foremost popular Docker Interview Questions asked in an interview. Below is the life cycle of the Docker container:

  • 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.

8. What are Docker Objects?

The Docker Objects are Docker Images, Services, and Docker Containers. A Docker Image may be a read-only template with the configuration or runtime instructions for the Docker container. The Services allow scaling the containers across the various Docker Daemons. These all together work as Swarm.

9. What are Docker Namespaces?

The Namespaces in Docker may be a technology which provides isolated workspaces called the Container. A layer of isolation for the Docker containers are provided by the namespace.

10. Briefly explain the Docker Container lifestyle?

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

11. Name some important Docker commands?

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 replacement image from the container changes

12. What is Docker Swarm?

Docker Swarm may be 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).

13. How to identify the status of a Docker Container?

To find the status of a Docker container,

“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.

14. What are the Docker Image and Docker Run Command?

A Docker Image may be a group of files and an amalgamation of parameters which permit the creation of instances that run in distinct containers as isolated processes. An image is essentially built using the instructions for an entire and executable version of an application, which relies on the host OS kernel. The Docker run command often wants to create the instance called container which may be run using the Docker image. When the Docker user runs a picture , it becomes one or multiple instances of that container.

15. Explain the use of Dockerfile?

It contains a bunch of instructions that are passed on Docker to make possible the build process of images, which may 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.

16. Which networks are all available by default in Docker?

The default networks available in Docker are:

bridge: Default network which the containers hook up with if the network isn’t specified otherwise

none: Connects to a container-specific network stack lacking a network interface

host: Connects to the host’s network stack

17. Explain how Docker is different from other container technologies.

Docker is one among the newest container technologies and has emerged together as the foremost popular. Built-in the age of cloud, Docker comes with an entire lot of latest features that were missing in older container technologies. One of the best 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 method to package and ship programs. Docker also features 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?

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. Explain the disparity between the commands ‘Docker run’ and ‘Docker create’?

The primary difference between Docker run and Docker create is that if you employ the latter, the container is made during a ‘stopped’ state. Also, Docker creates are often wont to store and output container ID to be used at a later time. The best thanks to roll in the hay is to use ‘docker run’ with —cidfile FILE_NAME as running it again won’t allow overwriting the file.

20. What is the difference between a registry and a repository?

The Docker Registry may be a service for hosting and distributing images, whereas the Docker Hub is that the default registry. On the opposite hand, the Docker Repository is a collection of Docker images that are related. That is, they have the same name but different tags.

21. Can JSON be used instead of YAML for the compose file in Docker? If yes, how?

Yes, JSON is often used rather than YAML for the Docker compose file. To use the JSON file with composing, the filename should be specified as the following:

“docker-compose -f docker-compose.json up”

22. Explain CMD and ENTRYPOINT in a Dockerfile?

In a Dockerfile, both CMD and ENTRYPOINT instructions define which commands are going to be executed while running a container. 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 alternate argument, CMD are going to be overridden

23. Explain the process to run an application inside a Linux Container using Docker

Below are the steps on the way to run an application inside the Linux Container using Docker

  • Install and run Docker
  • From the Docker hub Fetch Fedora 21 base image 
  • Load your application in the Docker base image
  • Using your new image in interactive mode it run container 
  • Check the containers in the system
  • Start or stop Docker container
  • Go inside a Docker container
  • Remove container or image

24. Which networks are all available by default in Docker?

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

25. How to build environment-agnostic systems with Docker?

There are three main features helping to realize that:

  • Volumes
  • Environment variable injection
  • Read-only file systems

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

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

That’s because it’s more transparent than ADD. COPY supports the essential copying of local files into the container, while ADD has some features that aren’t immediately obvious. Consequently, the simplest use for ADD is local tar file auto-extraction into the image, as in ADD rootfs.tar.xz /.

27. What is Docker hub?

It may be a cloud-based registry service which allows you to link to code repositories, build your images and test them,  links to Docker cloud, and stores manually pushed images so you can deploy images to your hosts. A centralized resource was provided for alter management and distribution, team collaboration and user, container image discovery, and workflow automation throughout the pipeline.

28. What are the most common instructions in Dockerfile?

Below are the some of the common instructions in Dockerfile:

  • FROM: We use FROM to line the bottom image for subsequent instructions. FROM is the first instruction, In every valid Dockerfile.
  • LABEL: We use LABEL to arrange our images as per project, module, licensing etc. We can also use LABEL to assist in automation.
  • In LABEL we specify a key value pair which will be later used for programmatically handling the Dockerfile.
  • RUN: We use the RUN command to execute any instructions in a new layer on top of the current image. With each RUN command on top of the image we add something 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 employed .

29. What type of applications – Stateless or Stateful are more suitable for Docker Container?

It is preferable to create a 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 the 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 far easier to scale with Docker Containers than a stateful application.

30. What is virtualisation?

In its conceived form, virtualisation was considered a way of logically dividing mainframes to permit multiple applications to run simultaneously. The net effect is that virtualization allows you to run two completely different OS on the same hardware. Each guest OS goes through the process of bootstrapping, loading kernel etc. 

You can have very tight security, for instance , guest OS can’t get full access to host OS or other guests and mess things up. The virtualization method can be categorized based on how it mimics hardware to a guest operating system and emulates guest operating environments. Primarily, there are three types of virtualization:

  • Emulation
  • Paravirtualization
  • Container-based virtualization

31. What is Hypervisor?

Virtualization can be established by Hypervisor software only. It segregates a system into several sections and assigns to operate every single section to function as a distinct system. Hypervisor will run from the existing system of a host and won’t require a separate OS from a server.

The rapid development of virtualization technologies, primarily in cloud, has driven the utilization of virtualization further by allowing multiple virtual servers to be created on one physical server with the help of hypervisors, like Xen, VMware Player, KVM, etc., and incorporation of hardware support in commodity processors, like Intel VT and AMD-V.

32. What is the process for creating a Docker container?

We can use any specific Docker image for creating a Docker container using the below command:

docker run -t -i command name

This command not only creates the container but also starts it for us. If we want to check whether the Docker container has been created or not, then we need to have the following command that will list all the Docker containers, along with the host on which the Docker containers run:

docker ps -a

33. What is the process for stopping and restarting a Docker container?

To stop a Docker container, we need to use the following command:

docker stop CONTAINER_ID

To restart a Docker container, we need to use the following command:

docker restart CONTAINER_ID

34. 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

35. What is Docker Engine?

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

36. Where the docker volumes are stored?

You need to navigate:

/var/lib/docker/volumes

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

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

38. How can you run multiple containers using a single service?

By using docker-compose, you’ll run multiple containers employing a single service. All docker-compose files use yaml language.

39. Can you lose data when the container exits?

No, any data that your application writes to the disk gets stored in the container. The filing system for the container persists even after the container halts.

40. What is the purpose of Docker_Host?

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

41. How to check for Docker Client and Docker Server version?

The below command gives you information about Docker Client and Server versions:

$ docker version

42. How do you get the number of containers running, paused and stopped?

You can use the following command to get detailed information about the docker installed on your system.

$ docker info

You can get the number of containers running, paused, stopped, the number of images and a lot more.

43. How to login into docker repository?

You can use the following command to login into hub.docker.com:

$ docker login

You’ll be prompted for your username and password, insert those and congratulations, you’re logged in.

44. How to delete an image from the local storage system?

The following command lets you delete an image from the local system:

$ docker rmi

45. How to build a Dockerfile?

Once you’ve written a Dockerfile, you need to build it to create an image with those specifications. Use the following command to build a Dockerfile:

$ docker build

The next question would be when do you use “.dockerfile_name” and when to use the entire path?

Use “.dockerfile_name” when the dockerfile exits within the same file directory and you employ the whole path if it lives elsewhere .

45. What platforms does docker run on?

This is a very straightforward question but can get tricky. Do some company research before going for the interview and determine how the corporate is using Docker. Make sure you mention the platform company is using in this answer.

Docker runs on various Linux administration:

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

It can also be used in production with Cloud platforms with the following services:

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

46. How many containers can run per host?

There are often as many containers as you would like per host. Docker does not put any restrictions on it. But you would like to think that every container needs space for storing , CPU and memory which the hardware must support. You also need to consider the application size. Containers are considered to be lightweight but very dependent on the host OS.

47. How will you monitor Docker in production?

Docker provides functionalities like docker stats and docker events to watch docker in production. The CPU and memory usage of the container provided by the Docker stats. Docker events provide information about the activities happening within the docker daemon.

48. Is there a way to identify the status of a Docker container?

There are six possible states a container can be at any given point – Created, Running, Paused, Restarting, Excited, Dead.

Use the subsequent command to see for docker state at any given point:

$ docker ps

The above command lists down only running containers by default. To look for all containers, use the following command:

$ docker ps -a

49. Can you remove a paused container from Docker?

The answer is no. You cannot remove a paused container. The container has to be in the stopped state before it can be removed.

50. Is it better to directly remove the container using the rm command or stop the container followed by removing the container?

It’s always better to stop the container and then remove it using the remove command.

$ docker stop

$ docker rm -f

Stopping the container and then removing it will allow sending SIG_HUP signal to recipients. This will ensure that all the containers have enough time to clean up their tasks. This method is considered a good practice, avoiding unwanted errors.

Add a Comment

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