• Home
  • DevOps
  • Top Docker Interview Questions and Answers

Top Docker Interview Questions and Answers

Last updated on Feb 18 2022
Rahul Sharma

Table of Contents

Top Docker Interview Questions and Answers

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.

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

What are the main drawbacks of Docker?

Some notable drawbacks of Docker are:

  • Doesn’t provide a storage option
  • Offer a poor monitoring option.
  • No automatic rescheduling of inactive Nodes
  • Complicated automatic horizontal scaling set up

What is memory-swap flag?

Memory-swap is a modified flag that only has meaning if- memory is also set. Swap allows the container to write express memory requirements to disk when the container has exhausted all the RAM which is available to it.

 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.

 How can you monitor the docker in production environments?

Docker states and Docker Events are used to monitoring docker in the production environment.

 What the states of Docker container?

Important states of Docker container are:

  • Running
  • Paused
  • Restarting
  • Exited

 What is Docker hub?

Docker hub is a cloud-based registry that which helps you to link to code repositories. It allows you to build, test, store your image in Docker cloud. You can also deploy the image to your host with the help of Docker hub.

 What is Virtualization?

Virtualization is a method of logically dividing mainframes to allow multiple applications to run simultaneously.

However, this scenario changed when companies and open source communities were able to offer a method of handling privileged instructions. It allows multiple OS to run simultaneously on a single x based system.

 What is Hypervisor?

The hypervisor allows you to create a virtual environment in which the guest virtual machines operate. It controls the guest systems and checks if the resources are allocated to the guests as necessary.

Explain Docker object labels

Docker object labels is a method for applying metadata to docker objects including, images, containers, volumes, network, swam nodes, and services.

 Write a Docker file to create and copy a directory and built it using python modules?

FROM pyhton:.-slim
WORKDIR /app
COPY . /app
docker build –tag

How to include code with copy/add or volumes?

In docker file, we need to use COPY or ADD directive. This is useful to relocate code. However, we should use a volume if we want to make changes.

 Explain the process of scaling your Docker containers

The Docker containers can be scaled to any level starting from a few hundred to even thousands or millions of containers. The only condition for this is that the containers need the memory and the OS at all times, and there should not be a constraint when the Docker is getting scaled.

What is the method for creating a Docker container?

You can use any of the specific Docker images for creating a Docker container using the below command.

docker run -t -i command name

This command not only creates the container but also start it for you.

 What are the steps for the Docker container life cycle?

Below are the steps for Docker life cycle:

  • Build
  • Pull
  • Run

 How can you run multiple containers using a single service?

By using docker-compose, you can run multiple containers using a single service. All docker-compose files uses yaml language.

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.

 What are the three components of Docker Architecture

  • Client
  • Docker-Host
  • Registry

What is client?

Docker provides Command Line Interface tools to the client to interact with Docker daemon.

 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.

 How do I run multiple copies of Compose file on the same host?

Compose uses the project name which allows you to create unique identifiers for all of a project’s containers and other resources. To run multiple copies of a project, set a custom project name using the -a command-line option or using COMPOSE_PROJECT_NAME environment variable.

What are Docker Images?

When you mention Docker images, your very next question will be “what are Docker images”.

Docker image is the source of Docker container. In other words, Docker images are used to create containers. When a user runs a Docker image, an instance of a container is created. These docker images can be deployed to any Docker environment.

 Explain Docker Architecture?

Docker Architecture consists of a Docker Engine which is a client-server application with three major components:

  1. A server which is a type of long-running program called a daemon process (the docker command).
  2. A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.
  3. A command line interface (CLI) client (the docker command).
  4. The CLI uses the Docker REST API to control or interact with the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the underlying API and CLI.

What is a Dockerfile?

Let’s start by giving a small explanation of Dockerfile and proceed by giving examples and commands to support your arguments.

Docker can build images automatically by reading the instructions from a file called Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build, users can create an automated build that executes several command-line instructions in succession.

What is Docker Machine?

Docker machine is a tool that lets you install Docker Engine on virtual hosts. These hosts can now be managed using the docker-machine commands. Docker machine also lets you provision Docker Swarm Clusters.

Docker Basic Commands

Once you’ve aced the basic conceptual questions, the interviewer will increase the difficulty level. So let’s move on to the next section of this Docker Interview Questions article. This section talks about the commands that are very common amongst docker users.

How to check for Docker Client and Docker Server version?

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

$ docker version

 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.

 If you vaguely remember the command and you’d like to confirm it, how will you get help on that particular command?

The following command is very useful as it gives you help on how to use a command, the syntax, etc.

$ docker –help

The above command lists all Docker commands. If you need help with one specific command, you can use the following syntax:

$ docker <command> –help

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.

 If you wish to use a base image and make modifications or personalize it, how do you do that?

You pull an image from docker hub onto your local system

It’s one simple command to pull an image from docker hub:

$ docker pull <image_name>

Can you use a container, edit it, and update it? Also, how do you make it a new and store it on the local system?

Of course, you can use a container, edit it and update it. This sounds complicated but its actually just one command.

$ docker commit <conatainer id> <username/imagename>

Once you’ve worked with an image, how do you push it to docker hub?

$ docker push <username/image name>

 How to delete an image from the local storage system?

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

$ docker rmi <image-id>

Where all do you think Docker is being used?

When asked such a question, respond by talking about applications of Docker. Docker is being used in the following areas:

  • Simplifying configuration: Docker lets you put your environment and configuration into code and deploy it.
  • Code Pipeline Management: There are different systems used for development and production. As the code travels from development to testing to production, it goes through a difference in the environment. Docker helps in maintaining the code pipeline consistency.
  • Developer Productivity: Using Docker for development gives us two things – We’re closer to production and development environment is built faster.
  • Application Isolation: As containers are applications wrapped together with all dependencies, your apps are isolated. They can work by themselves on any hardware that supports Docker.
  • Debugging Capabilities: Docker supports various debugging tools that are not specific to containers but work well with containers.
  • Multi-tenancy: Docker lets you have multi-tenant applications avoiding redundancy in your codes and deployments.
  • Rapid Deployment: Docker eliminates the need to boost an entire OS from scratch, reducing the deployment time.

 How is Docker different from other containerization methods?

Docker containers are very easy to deploy in any cloud platform. It can get more applications running on the same hardware when compared to other technologies, it makes it easy for developers to quickly create, ready-to-run containerized applications and it makes managing and deploying applications much easier. You can even share containers with your applications.

If you have some more points to add you can do that but make sure the above explanation is there in your answer.

How far do Docker containers scale? Are there any requirements for the same?

Large web deployments like Google and Twitter and platform providers such as Heroku and dotCloud, all run on container technology. Containers can be scaled to hundreds of thousands or even millions of them running in parallel. Talking about requirements, containers require the memory and the OS at all the times and a way to use this memory efficiently when scaled.

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 find out how the company is using Docker. Make sure you mention the platform company is using in this answer.

Docker runs on various Linux administration:

  • Ubuntu ., . et al
  • Fedora /+
  • RHEL .+
  • CentOS +
  • Gentoo
  • ArchLinux
  • openSUSE .+
  • CRUX .+

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

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

How many containers can run per host?

There can be as many containers as you wish per host. Docker does not put any restrictions on it. But you need to consider every container needs storage space, CPU and memory which the hardware needs to support. You also need to consider the application size. Containers are considered to be lightweight but very dependant on the host OS.

 Is it a good practice to run stateful applications on Docker?

The concept behind stateful applications is that they store their data onto the local file system. You need to decide to move the application to another machine, retrieving data becomes painful. I honestly would not prefer running stateful applications on Docker.

 Suppose you have an application that has many dependant services. Will docker compose wait for the current container to be ready to move to the running of the next service?

The answer is yes. Docker compose always runs in the dependency order. These dependencies are specifications like depends_on, links, volumes_from, etc.

 What’s the difference between virtualization and containerization?

Virtualization is an abstract version of a physical machine, while containerization is the abstract version of an application.

 Last simple question…Describe a Docker container’s lifecycle.

Although there are several different ways of describing the steps in a Docker container’s lifecycle, the following is the most common:

  1. Create container
  2. Run container
  3. Pause container
  4. Unpause container
  5. Start container
  6. Stop container
  7. Restart container
  8. Kill container

List some of the more advanced Docker commands and what they do.

Some advanced commands include:

  • Docker info. Displays system-wide information regarding the Docker installation
  • Docker pull. Downloads an image
  • Docker stats. Provides you with container information
  • Docker images. Lists downloaded images

 Can you lose data stored in a container?

Any data stored in a container remains there unless you delete the container.

 What platforms can you run Docker on?

The Linux platforms are:

  • ArchLinux
  • CentOS +
  • CRUX .+
  • Fedora /+
  • Gentoo
  • openSUSE .+
  • RHEL .+
  • Ubuntu ., . et al

Which is the best method for removing a container: the command “stop container” followed by the command “remove container,” the rm command by itself?

Stop the container first, then remove it. Here’s how:

  • $ docker stop <coontainer_id>
  • $ docker rm -f <container_id>

 Can a container restart on its own?

Since the default flag -reset is set to false, a container cannot restart by itself.

 How do Docker daemon and the Docker client communicate with each other?

You use a combination of Rest API, socket.IO, and TCP to facilitate communication.

 Can you implement continuous development (CD) and continuous integration (CI) in Docker?

Yes, you can. You can run Jenkins on Docker and use Docker Compose to run integration tests.

 Finally, how do you create a Docker swarm?

Use the following command: docker swarm init –advertise-addr <manager IP>

Explain the Docker Registry in detail.

 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.

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

 Name some important Docker commands

Below is 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

 What are Namespaces in Docker.

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.

What is termed as Docker Objects?

Docker Images, Services, and Containers are termed as Docker Objects.

  • Images: A read-only template with instructions for creating a Docker container
  • Containers: A runnable instance of an image
  • Services: It allows the scaling of containers across a variety of Docker Daemons, which all work together as a swarm.

Other Docker Objects include Networks and Volumes.

 Which is more suitable for Docker Container, Stateless or Stateful application?

 Stateless applications should be preferred over a Stateful application for Docker Container. We can create one container from our application and take out the app’s configurable state parameters. Once it is one, we can run the same container with different production parameters and other environments. Through the Stateless application, we can reuse the same image in distinct scenarios. It is also easier to scale a Stateless application than a Stateful application when it comes to Docker Containers.

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.

How is Docker monitored in production?

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 are called with a container ID, it returns the container’s CPU and memory usage. 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.

What is Virtualization?

 Virtualization, in its earlier days, was termed as a method of logically dividing mainframes to allow multiple applications to run concurrently. But as time progressed and the industry was able to allow for multiple operating systems to be run simultaneously on a single x based system, the meaning of virtualization changed considerably.

The net result? Virtualization allows the user to run two different OS on the same hardware. While the primary OS is the administrator, every guest OS goes through the processes such as bootstrapping, loading kernel, and more. It is also perfect for security, as every guest OS may not be allowed full access to the host OS, leading to the data breach.

There are primarily three types of virtualization:

  • Paravirtualization
  • Emulation
  • Container-based virtualization

 What is the difference between a registry and a repository?

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

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

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

  • Install and run Docker
  • Fetch Fedora  (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 is a Hypervisor?

 A Virtual machine monitor, known as Hypervisor, is software to create and run virtual machines. It allows a single host computer to support more than one guest VMs. This is done by sharing resources like memory, processing, etc., thus reducing the memory, space, and maintenance requirements. There are two types of hypervisor:

  • Type I: it is like a lightweight operating system that runs on the host’s hardware.
  • Type II: runs like software programs on an operating system.

Explain the main difference between containerization and virtualization.

Through virtualization, you can run many operating systems on a single physical server. Containerization occurs on the same operating system, where applications are packaged as containers and run under a single server or VM.

Explain Docker Images, Docker Hub, Docker File?

Docker images: These are files that contain multiple layers and are used to execute code inside the Docker container. Images are built from instructions for an executable version of an application. Images speed up docker build by allowing each step to be cached.;

Docker hub: It is a service that finds and shares container images within a team. You can push and pull images, access private repositories of container images, build container images automatically from GitHub (or Bitbucket), and push them to Docker Hub. Docker itself provides the service. Read more.

Docker file: It is a text document used to build an image. It contains instructions and commands to build the image. Docker reads the commands and assembles the image automatically.

How to Check for Docker Client and Docker Server version?

 We can check the docker version using the command docker version [options]. If we do not give any options, then Docker gives all the version related information about client and server. For example, to get only the server version, use:

$ docker version —format ‘{{.Server.Version}}

Explain various Docker Basic Commands?

Some Docker commands are:

  • docker push: pushes repository or image to a registry
  • docker run: runs a command in a new container
  • docker pull: pulls repository or image from a registry
  • docker start: starts one or more containers
  • docker stop: stops running containers
  • docker search: searches for an image in a docker hub
  • docker commit: commits new image

 Explain how Docker Container is different from other containerization methods?

 Docker containers can be easily deployed to any cloud platform. Also, developers can create ready-to-run containerized applications faster and manage and deploy applications easily. Containers can also be shared with applications. These features are not present in other containerization methods.

Is it possible for the cloud to overtake the use of Containerization?

In this type of question, you can give your personal opinion. For example, as per my understanding, although the cloud is a good competitor, it cannot replace containerization. Most companies are using cloud and containerization in tandem to get the best out of both technologies.

What are the various possible states of the Docker Container?

 The different states of the Docker container are:

  • Created – a container that is created but not active.
  • Restarting – a container that is in the process of getting restarted.
  • Running – running container.
  • Paused – container whose processes are paused.
  • Exited – a container that ran and completed.

Explain the memory-swap flag?

A memory-swap flag is a modifier flag that allows a container to write excess memory requirements into a disk when it has used all the available RAM. It is set only when the –memory flag is set. Example, if memory = “m” and memory-swap = “g”, then the container can use m of memory and swap of m (g-m).

Where are the docker volumes stored?

Volumes are created and managed by Docker (not to be accessed by Non-Docker processes) and are stored in a part of Docker host filesystem: /var/lib/docker/volumes/. Volumes are the most efficient way to persist data in Docker.

 Explain the various Docker Advanced Commands?

Some important Docker commands are:

  • docker -version: to know the installed docker version. Syntax, Docker –version
  • docker ps: lists all the docker containers that are running along with the container details. Syntax: docker ps
  • docker ps -a: lists all the containers, including those that are running, stopped, exited, along with the details. Syntax: docker ps -a
  • docker exec: Access the container and run commands inside that container. Syntax: docker exec [options]
  • docker build: builds an image from Dockerfile. Syntax: docker build [options] path|URL
  • docker rm: Removes the container with the mentioned container id. Syntax: docker rm <container_id>
  • docker rmi: Removes the docker image with the mentioned image id. Syntax: docker rmi <image_id>
  • docker info: Gets detailed information about Docker installed on the system like the number of containers, images, running, paused, stopped, server version, volume, runtimes, kernel version, total memory etc. Syntax: docker info;
  • docker cp: Copies a file from a docker container to a local system. Syntax: docker cp <source_path> <dest_path>
  • docker history: displays the history of the docker image with the mentioned image name. Syntax: docker history <img_name>

What are the commands to control Docker with Systemd

 To start the Docker daemon, many Linux distributions use the system. To start the services, use the command systemct. If systemct is not available, the service command is used.;

$ sudo systemctl start docker
$ sudo service docker start

To enable and disable a daemon during boot time, use:

$ sudo systemctl enable docker
$ sudo systemctl disable docker

To modify daemon options, use:;

$ sudo systemctl edit docker

To view logs related to Docker service:

$ journalctl -u docker;

  • Dead – a container that the daemon tried and failed to stop.

Tell us about the steps for the Docker container life cycle.

Here are the steps:

  • Create container: docker create –name <container-name> <image-name>
  • Run docker container: docker run -it -d –name <container-name> <image-name> bash
  • Pause container: docker pause <container-id/name>
  • Unpause container: docker unpause <container-id/name>
  • Start container: docker start <container-id/name>
  • Stop container: docker stop <container-id/name>
  • Restart container: docker restart <container-id/name>
  • Kill container: docker kill <container-id/name>
  • Destroy container: docker rm <container-id/name>

What is CNM?

 CNM or Container Network Model is a specification that formally defines the steps needed to provide networking for containers while maintaining abstraction used to support multiple network drivers. CNM is built on three components, namely, sandbox, endpoint, and Network.

What are the different kinds of mount types available in Docker?

The three types are:

  • Bind mounts: These can be stored anywhere on the host system
  • Volume mount: they are managed by Docker and are stored in a part of the host filesystem.
  • tmpfs mount: they are stored in the host system’s memory. These mounts can never be written to the host’s filesystem.

Explain Docker object labels.

 Docker object label is a key-value pair that is stored as a string. We can apply metadata using labels. Labels can be applied for Docker objects like images, containers, volumes, networks, local daemons, swarm nodes, and services. The key-value pair should be unique for each object. Labels are static for the entire lifetime of the object.

  Which networks 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

 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.

 Explain Registries

There are two types of registry is

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

 What command should you run to see all running container in Docker?

$ docker ps

 Write the command to stop the docker container

$ sudo docker stop container name

 What is the command to run the image as a container?

$ sudo docker run -i -t alpine /bin/bash

 What are the common instruction in Dockerfile?

The common instruction in Dockerfile are: FROM, LABEL, RUN, and CMD.

 Where the docker volumes are stored?

You need to navigate:

/var/lib/docker/volumes

 List out some important advanced docker commands

d1

 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.

 Explain Implementation method of Continuous Integration (CI) and Continues Development (CD) in Docker?

You need to do the following things:

  • Runs Jenkins on docker
  • You can run integration tests in Jenkins using docker-compose

 What are the command to control Docker with Systemd?

systemctl start/stop docker

service docker start/stop

 How to use JSON instead of YAML compose file?

docker-compose -f docker-compose.json up

 What is the command you need to give to push the new image to Docker registry?

docker push myorg/img

 What is CNM?

CNM stands for Container Networking Model. It is a standard or specification from Docker, Inc. that forms the basis of container networking in a Docker environment. This docker’s approach provides container networking with support for multiple network drivers.

 Does Docker offer support for IPV?

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

 Can you lose data when the container exits?

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

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

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

How to configure the default logging driver under Docker?

To configure the Docker daemon to default to a specific logging driver. You need to set the value of log-driver to the name of the logging drive the daemon.jason.fie.

Explain Docker Trusted Registry?

Docker Trusted Registry is the enterprise-grade image storage toll for Docker. You should install it after your firewall so that you can securely manage the Docker images you use in your applications.

 What is a Docker Container?

Docker containers include the application and all of its dependencies. It shares the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers are not tied to any specific infrastructure: they run on any computer, on any infrastructure, and in any cloud. Docker containers are basically runtime instances of Docker images.

Tell us something about Docker Compose.

Docker Compose is a YAML file which contains details about the services, networks, and volumes for setting up the Docker application. So, you can use Docker Compose to create separate containers, host them and get them to communicate with each other. Each container will expose a port for communicating with other containers.

 What is Docker Swarm?

You are expected to have worked with Docker Swarm as it’s an important concept of Docker.

Docker Swarm is native clustering for Docker. It turns a pool of Docker hosts into a single, virtual Docker host. Docker Swarm serves the standard Docker API, any tool that already communicates with a Docker daemon can use Swarm to transparently scale to multiple hosts.

 What is the lifecycle of a Docker Container?

This is one of the most popular questions asked in Docker interviews. Docker containers have the following lifecycle:

  • 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

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.

 If you wish to use a base image and make modifications or personalize it, how do you do that?

You pull an image from docker hub onto your local system

It’s one simple command to pull an image from docker hub:

$ docker pull <image_name>

 How do you create a docker container from an image?

Pull an image from docker repository with the above command and run it to create a container. Use the following command:

$ docker run -it -d <image_name>

Most probably the next question would be, what does the ‘-d’ flag mean in the command?

-d means the container needs to start in the detached mode. Explain a little about the detach mode. Have a look at this blog to get a better understanding of different docker commands.

How do you list all the running containers?

The following command lists down all the running containers:

$ docker ps

 Suppose you have  containers running and out of these, you wish to access one of them. How do you access a running container?

The following command lets us access a running container:

$ docker exec -it <container id> bash

The exec command lets you get inside a container and work with it.

 How to start, stop and kill a container?

The following command is used to start a docker container:

$ docker start <container_id>

and the following for stopping a running container:

$ docker stop <container_id>

kill a container with the following command:

$ docker kill <container_id>

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 <path to docker file>

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 in the same file directory and you use the entire path if it lives somewhere else.

Do you know why docker system prune is used? What does it do?

$ docker system prune

The above command is used to remove all the stopped containers, all the networks that are not used, all dangling images and all build caches. It’s one of the most useful docker commands.

 Will you lose your data, when a docker container exists?

No, you won’t lose any data when Docker container exits. Any data that your application writes to the container gets preserved on the disk until you explicitly delete the container. The file system for the container persists even after the container halts.

 Where all do you think Docker is being used?

When asked such a question, respond by talking about applications of Docker. Docker is being used in the following areas:

  • Simplifying configuration: Docker lets you put your environment and configuration into code and deploy it.
  • Code Pipeline Management: There are different systems used for development and production. As the code travels from development to testing to production, it goes through a difference in the environment. Docker helps in maintaining the code pipeline consistency.
  • Developer Productivity: Using Docker for development gives us two things – We’re closer to production and development environment is built faster.
  • Application Isolation: As containers are applications wrapped together with all dependencies, your apps are isolated. They can work by themselves on any hardware that supports Docker.
  • Debugging Capabilities: Docker supports various debugging tools that are not specific to containers but work well with containers.
  • Multi-tenancy: Docker lets you have multi-tenant applications avoiding redundancy in your codes and deployments.
  • Rapid Deployment: Docker eliminates the need to boost an entire OS from scratch, reducing the deployment time.

 How is Docker different from other containerization methods?

Docker containers are very easy to deploy in any cloud platform. It can get more applications running on the same hardware when compared to other technologies, it makes it easy for developers to quickly create, ready-to-run containerized applications and it makes managing and deploying applications much easier. You can even share containers with your applications.

If you have some more points to add you can do that but make sure the above explanation is there in your answer.

Can I use JSON instead of YAML for my compose file in Docker?

You can use JSON instead of YAML for your compose file, to use JSON file with compose, specify the JSON filename to use, for eg:

$ docker-compose -f docker-compose.json up

 How have you used Docker in your previous position?

Explain how you have used Docker to help rapid deployment. Explain how you have scripted Docker and used it with other tools like Puppet, Chef or Jenkins. If you have no past practical experience in Docker and instead have experience with other tools in a similar space, be honest and explain the same. In this case, it makes sense if you can compare other tools to Docker in terms of functionality.

 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, Exited, Dead.

Use the following command to check 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

 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.

Can a container restart by itself?

No, it’s not possible for a container to restart by itself. By default the flag -restart is set to false.

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

Its always better to stop the container and then remove it using the remove command.

$ docker stop <coontainer_id>
$ docker rm -f <container_id>

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.

 Will cloud overtake the use of Containerization?

Docker containers are gaining popularity but at the same time, Cloud services are giving a good fight. In my personal opinion, Docker will never be replaced by Cloud. Using cloud services with containerization will definitely hype the game. Organizations need to take their requirements and dependencies into consideration into the picture and decide what’s best for them. Most of the companies have integrated Docker with the cloud. This way they can make the best out of both the technologies.

How will you monitor Docker in production?

Docker provides functionalities like docker stats and docker events to monitor docker in production. Docker stats provides CPU and memory usage of the container. Docker events provide information about the activities taking place in the docker daemon.

 Is it a good practice to run Docker compose in production?

Yes, using docker compose in production is the best practical application of docker compose. When you define applications with compose, you can use this compose definition in various production stages like CI, staging, testing, etc.

What changes are expected in your docker compose file while moving it to production?

These are the following changes you need make to your compose file before migrating your application to the production environment:

  • Remove volume bindings, so the code stays inside the container and cannot be changed from outside the container.
  • Binding to different ports on the host.
  • Specify a restart policy
  • Add extra services like log aggregator

 Are you aware of load balancing across containers and hosts? How does it work?

While using docker service with multiple containers across different hosts, you come across the need to load balance the incoming traffic. Load balancing and HAProxy is basically used to balance the incoming traffic across different available(healthy) containers. If one container crashes, another container should automatically start running and the traffic should be re-routed to this new running container. Load balancing and HAProxy works around this concept.

 What are Docker’s most notable features?

Docker’s most essential features include:

  • Application agility
  • Developer productivity
  • Easy modeling
  • Operational efficiencies
  • Placement and affinity
  • Version control

 Why should anyone use Docker? What does it offer?

Docker gives users many incentives for adoption, such as:

  • An efficient and easy initial set up experience
  • The means to describe an application lifecycle in detail
  • Simple configuration and smooth interaction with Docker Compose
  • Complete and well-detailed documentation
  • Ability to run on a PC or enterprise IT system with equal ease

 What about the opposite? Does Docker have any downsides?

Docker isn’t perfect. It comes with its share of drawbacks, including:

  • Lacks a storage option
  • Monitoring options are less than ideal
  • You can’t automatically reschedule inactive nodes
  • Automatic horizontal scaling set up is complicated

 What are Docker object labels?

Labels are the mechanism for applying metadata to Docker objects such as containers, images, local daemons, networks, volumes, and nodes.

 How do you find stored Docker volumes?

Use the command: /var/lib/docker/volumes

 How do you check the versions of Docker Client and Server?

This command gives you all the information you need: $ docker version

Show how you would create a container from an image.

To create a container, you pull an image from the Docker repository and run it using the following command: $ docker run -it -d <image_name>

 How about a command to stop the container?

Use the following command: $ sudo docker stop container name

 How would you list all of the containers currently running?

Use the command: $ docker ps

 What’s involved in scaling a Docker container?

Docker containers have the potential to be scaled to any level needed. Thanks to the platform’s flexibility, you can have anything from a few hundred to a few thousand, to millions of containers, providing they all have continual, unconstrained access to the required memory and OS.

 What do you know about the Docker system prune?

It’s a command used to remove all stopped containers, unused networks, build caches, and dangling images. Prune is one of the most useful commands in Docker. The syntax is:  $ docker system prune

Docker can also run on the following cloud-based platforms:

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

 Explain the components of Docker Architecture.

 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.

What is Docker Swarm?

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

 How to identify the status of a Docker Container?

 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.

 What are the Docker Image and Docker Run Command?

 A Docker Image is a group of files and an amalgamation of parameters that 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.

State the functionalities and applications of Docker.

 Below is some functionalities and applications of implementing Docker:

  • It makes the configuration simpler and provides ease of configuration at the infrastructure level
  • By helping the developer concentrate exclusively on business logic, it reduces development time and increases productivity
  • It amplifies the debugging capabilities which provide useful functionalities
  • It allows the isolation of the application
  • It reduces the use of multiple servers in the form of containerization
  • It facilitates rapid deployment at the OS level

Explain the use of Dockerfile.

Dockerfile contains many instructions 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 to create an image.

List the steps in a deploy process for Dockerized Apps stored In A Git Repo.

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

Explain how Docker is different from other container technologies.

Docker is one of the latest container technologies and has emerged as one of the most popular. Built-in the cloud era, Docker comes with a lot of new features that were missing in older container technologies. One of Docker’s finest features 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.

Shed some light on the workflow of Docker usage.

Below is a brief explanation of the workflow of Docker usage:

  • Since the Dockerfile is the source code of the image, everything starts with it
  • Once it is created, the Dockerfile is used to build the image of the container. This image is only the compiled version of the Dockerfile
  • This image is then redistributed using the registry, which is like a repository of images.
  • Further, the image can be used to run containers. A container, while it is running, is very similar to a VM without the hypervisor.

Explain the disparity between the commands ‘Docker run’ and ‘Docker creates.’

The primary difference between Docker run and Docker create is that if you use the latter, the container is created in a ‘stopped’ state. Also, Docker creates can be used to store and output container ID for use later. The best way to do it is to use ‘docker run’ with —cidfile FILE_NAME as running it again won’t allow overwriting the file.

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

Yes, JSON can be used instead of 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.”

Explain CMD and ENTRYPOINT in a Dockerfile?

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

Explain the login procedure to Docker Repository?

 To log in to the Docker repository, use the following command:

docker login [OPTIONS] [SERVER]

For example, to login to a self-hosted (local) registry, you can add the server name:

$ docker login localhost:

  List out the platform where Docker runs on.

 It runs on Windows (x-) and Linux (on x-, ARM, and other CPU architectures), sx, ppcle.

 Is it possible for a container to restart by itself?

 Yes, it is possible. Docker defines certain policies to restart the container. These are Off: container won’t be restarted if it stops or fails,

  • On-failure: container restarts only when a failure that occurred is not due to the user,
  • Unless-stopped: container restarts only when a user executes the command to stop it,
  • Always: the container is always restarted irrespective of error or other issues.

The command is:

$ docker run -dit — restart [unless-stopped|off|on-failure|always] [CONTAINER]

  Explain the container orchestration and why we need to use it?

 Container orchestration helps in managing the containers running in a dynamic and large environment. Container orchestration can control and automate the following tasks:

  • Provisioning and deployment of containers,
  • Load balancing,
  • Allocation of resources between containers,
  • Monitoring the health of containers and hosts,
  • Scaling of containers,
  • Switching containers from one host to another when the host is unavailable or lacking resources.

  What is the process of scaling your Docker containers

Docker containers can be scaled using Docker-decompose’s scale command. The process is as follows:

  • Scale the server container and start ‘n’ instances of the server using:

$] docker-compose –file docker-compose-run-srvr.yml scale <service_name>=<n>

In the above command, the service name is defined in docker-compose-run-srvr.yml and are scaling it to ‘n’ times, where n can be any integer value.

  • After scaling the Docker container, to check the container details, execute the following command:

$] docker ps -a

 Is it possible to run multiple copies of a Compose file on the same host? How?

This is done through the use of docker-compose. With Docker Compose, we can use a YAML file to configure the application’s services. After this, with a single command, all the services can be created and started. To use Compose, follow the below steps:

  • Define the app environment in the Dockerfile so that it can be replicated anywhere
  • Define all the services of your application in the docker-compose.yml file.;
  • Run docker-compose up to create and start the entire app.

So, this brings us to the end of the Docker Interview Questions blog.This Tecklearn ‘Top Docker Interview Questions and Answers’ helps you with commonly asked questions if you are looking out for a job in Docker or DevOps Domain. If you wish to learn Docker and build a career in DevOps domain, then check out our interactive Containerization using Docker Training, that comes with 24*7 support to guide you throughout your learning period.

https://www.tecklearn.com/course/containerization-using-docker/

Containerization using Docker Training

About the Course

Tecklearn has specially designed this Containerization using Docker Training Course to advance your skills for a successful career in this domain. his Docker training online course will help you learn Docker containerization, running Docker containers, Docker image creation, Dockerfile, Docker orchestration, security best practices and more through hands-on projects and case studies. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Docker.

Why Should you take Containerization using Docker Training?

  • Average salary of Docker Expert is $110k – Indeed.com
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.
  • Intuit, PayPal, Splunk, Uber & many other MNC’s worldwide use Docker across industries

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Containerization using Docker – Part 1

  • Introduction to Docker
  • Understanding Docker Lifecycle
  • Docker Architecture
  • Components of Docker Ecosystem
  • Common Docker Operations
  • Committing changes in a Container
  • Hands On

Containerization using Docker – Part 2

  • Building Custom Docker Images
  • Docker Image
  • Introduction to Docker Swarm
  • Deploying a 2-Node Cluster using Docker Swarm
  • Hands on

Got a question for us? Please mention it in the comments section and we will get back to you.

 

 

0 responses on "Top Docker Interview Questions and Answers"

Leave a Message

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