Register Login

Top Docker Interview Questions and Answers for 2019

Updated Jun 21, 2019

What is Docker?

Docker is a combination of SaaS and PaaS products that are used for developing and deploying software applications using packages called Containers.

Docker is like a virtual machine but does not create a new virtual operating system. It uses the Linux kernel where the application is running and requires the application to be shipped with the libraries that are not on the host system.

What is the use of Docker?

The different uses of Docker are:

  • It simplifies the configuration management as the Docker applications can be run on any environment. This is due to the environment setting and code are deployed together
  • It helps in isolating two applications running simultaneously by executing them under different containers.
  • It offers better server consolidation that Virtual machines
  • It helps to set up local development environments like the production environment for developers working in different setups

What language is Docker written in?

Docker is written in the Go programming language. It is a simple and powerful language that can be used easily to combine Docker with other environments.

How will you check the version of installed Docker?

The following commands have to be used for checking the version of Docker:

  • Type docker –v in the command line to check the client version
  • Type docker version in the command line to check the client and server version 

What is the difference between Docker image and Docker container?

Docker image is a file that has many layers and is used to run code within a Docker container. This image is made up of instructions that are required for an executable version of an application. For this code, the user constructs each image with tools and libraries.

A Docker container is a package that has all the required dependencies and libraries so that the code is executed easily on any environment.

How to start Docker daemon?

To run the Docker daemon, Docker has to be executed first by the executable file present in the C drive. Then, Docker can be stopped for Windows and the daemon can be run directly through the dockerd.exe.

What is a Docker image and where do Docker Store images?

Docker image is a file that has many layers and is used to run code within a Docker container. This image is made up of instructions that are required for an executable version of an application. For this code, the user constructs each image with tools and libraries.

By default, the images are stored in /var/lib/docker/aufs directory under the auf file, whereas the diff file contains the image contents.

How to SSH into a Docker container?

The steps to SSH into a Docker container are as follows:

  • Type the docker ps command to obtain the container name
  • For obtaining a bash shell within the container, type in the docker exec -it <container name> /bin/bash command
  • Use docker exec -it <container name> <command> to run commands specified within the container

What is Docker Hub?

Docker hub is like GitHub that stores container images that can be tested, shared and downloaded by users over the cloud. Public code repositories can be accessed through this hub and users can upload their own images.

What is Entrypoint in Docker?

The ENTRYPOINT instruction is similar to the CMD and is used to mention the command that has been executed when a container initializes. However, the instruction does not allow command overriding. If something is mentioned at the end of the docker end command, it will be added to the ENTRYPOINT instruction.

What is Docker machine?

The Docker Machine allows the users to install the Docker engine on different virtual systems and handle them through the docker commands. Using this, Docker hosts can be developed on local systems, a network, and datacenter or cloud providers such as AWS or Digital Ocean.

What is Docker Compose?

Docker Compose is a tool that is used for executing and creating definitions of Docker applications that have multiple layers. The application’s services are modified using a YAML file in Compose. It is applicable to all environments like development, testing, staging, and production.

What are the main features of Docker Compose?

Some important features of Docker compose are:

  • It can be used to develop many environments on one host server. These environments can be run by isolating them by a project name
  • During container creation, if docker finds any container from previous executions the volumes are copied into the new containers. This preserves the data ion volumes.
  • Changed containers can also be recreated.
  • As it supports the variable in the compose file, container variations can be performed.

What is Docker swarm?

The docker swarm is used for scheduling and clustering containers. Using this, a cluster of docker nodes can be used as a virtual system. The Swarm mode exists between the operating system and the docker images.

For scheduling containers, an IT administrator uses a Swarm manager to handle a swarm.

How to create Docker swarm?

Steps to create a swarm are:

  • In the terminal, SSH into the machine where the manager node has to be executed using the command $ docker-machine ssh manager1.
  • Create new swarm by the following code by using the command $ docker swarm init --advertise-addr <MANAGER-IP>
  • To see the present state of the swarm, run the docker info command
  • For viewing data about the swarm, run the docker node ls command

What are Docker containers?

A Docker container is a package that has all the required dependencies and libraries so that the code is executed easily on any environment. It uses the system’s kernel and does not need as an operating system for the application. The applications are secured this way.

What are the main security concerns with Docker-based container?

For docker containers, the users are not namespaced. So if any process that breaks out of the container will get the same privileges as the host, like that of the container. So a hacker can gain access to both the container and the host by a privilege escalation attack.

Hackers can also get access to the password or username the container requires while accessing a database. This is a problem as they can get access to the service.

Where are docker containers stored?

After accessing the docker machine with the command docker-machine ssh, the docker containers can be found at sudo ls /var/lib/docker/containers.

What is ONBUILD command in Docker?

When a newly developed docker image uses an image as a base for another image, the commands that need to be run are mentioned using the ONBUILD command. This command adds a trigger instruction along with the image to be used later when it is used as a base image.

What is the difference between Add and Copy command in a Dockerfile?

  • The Copy command takes the source and destination information. It allows the user to copy a file from the host machine to the Docker image.
  • The Add command allows the same functionality but an URL can be copied instead of a file or directory. Additionally, a tar file can be extracted directly into the destination, from the source.


×