Docker - Interview Questions

What is Docker?

 FAQ

Docker is a platform for developing, shipping, and running applications - which significantly reduces the time between developing the application and running it in production.

Docker provides the capability to package your application code and run it in an isolated environment called the container. You can package and run the container in your local machine, share or ship the container, and deploy and run the same container in lower and production environments. This streamlining of development life-cycle makes containers ideal for continuous integration and continuous delivery (CI/CD) workflows.

Docker containers are light weight, fast, and multiple containers can simultaneously run on the same host. You can easily bring up new containers or bring down running containers - making it easy to scale up or down. This makes Docker containers ideal for cloud base deployments.

What are the key architectural components of Docker?

 FAQ

Docker uses a client-server architecture. Following are the key architectural components of Docker.

Docker daemon - Docker daemon does the heavy lifting of building, running, and distributing Docker containers. Docker daemon listens to Docker client API requests and manages Docker objects such as images and containers.

Docker Client - Docker users interact with Docker via Docker client. Docker client sends user docker commands such as 'docker run' or 'docker push' to the Docker daemon which executes the commands.

Docker Registries - Docker registry stores Docker images, which are templates for creating Docker containers. Docker provides a public registry called Docker Hub that anyone can use. Docker looks for an image on Docker Hub by default.

What is the difference between Docker images and Docker Containers?

 FAQ

Docker image is a template with instructions for creating a Docker container. An image can be based on another image, with added customizations.

Docker container is a runnable instance of an image that can be created, started, stopped or deleted using the Docker API or Docker CLI.

What is the difference between Docker Containers and Virtual Machines?

 FAQ

Docker is based on container-based technology where the container contains all the dependencies and libraries used to run an application. Docker containers share the Host OS Kernel and multiple containers run on a single OS. Since Docker containers share the Host OS, they are light-weight, small in size, have fast boot-up times, and are easily portable.

Virtual Machines (VMs) are based on virtualization technology which uses the user space and Host OS Kernel. Unlike Docker containers VMs do not share the OS kernel and each VM requires a complete host kernel. Since Host OS and dependencies have to be included with the VM, they are heavy-weight, larger in size, have slower boot-up times, and difficult to share.

Describe the background process when you execute the docker run command, say 'docker container run --publish 80:80 nginx'?

 FAQ

When you run the 'docker container --publish 80:80 nginx' command, the following steps are processed by docker

1. Check for the nginx image file in the local image cache.

2. If it does not find in the local image cache then it looks at the remote image repository, which is by default docker hub

3. Downloads the latest version of nginx image from docker hub.

4. Create new container based on the downloaded nginx image.

5. Assigns a virtual IP for the container in a private network inside docker engine.

6. Since we specified --publish option with ports 80:80, opens port 80 on host and forwards to port 80 on container.

7. Starts the container by executing the CMD in the image file.

How do you see the list of containers in a docker engine?

 FAQ

You can see the list of running containers by using the ls command - docker container ls.

You can see the list of all containers (running and non-running) by using the ls command with the -a option - docker container ls -a.

> docker container ls
> docker container ls -a

How do you access a running container via shell, say with bash?

 FAQ

You can get access to the shell command of a running container using the exec command. For example, to access the bash shell of a container that is running nginx you can use the command - docker container exec -it nginx bash

> docker container exec -it nginx bash

How do you access a running container via shell, say with bash?

 FAQ

You can get access to the shell command of a running container using the exec command. For example, to access the bash shell of a container that is running nginx you can use the command - docker container exec -it nginx bash

> docker container exec -it nginx bash

How do you create a new virtual network and run a docker container in that network?

 FAQ

You can create a new virtual network in docker using the create command - docker network create my_new_network

You can then run a container in the newly created virtual network by using the run command with the --network option - docker container run nginx --network my_new_network

> docker network create my_new_network
> docker container run nginx --network my_new_network

What is the difference between docker image id and image tag?

 FAQ

Docker image id is a unique id given to an image. Image Ids are unique and are not shared across different images.

Docker image tag is a label or nickname given to an Image. Image tags can be used for versioning images. Same tag can be used across different images.

What is a Dockerfile?

 FAQ

Dockerfile is a text file containing a sequence of instructions or commands that are needed to build a Docker image.

Dockerfile must adhere to a specific format and set of instructions specified by Docker.

Each Dockerfile instruction is a considered as a layer. The layers are stacked and each layer is a delta of the changes from the previous layer.

What storage options does Docker provide to persist and share data across containers?

 FAQ

By default any file created inside a container is stored on a writable layer within the container. That means the data is lost when the container is removed, and also the data cannot be shared with other processes.

Docker provides two storage options to store files in the host machine, so that these files can be shared across containers and processes. Theses two storage options are Volumes and Bind mounts

What is the difference between Data Volumes and Bind mount?

 FAQ

Volumes - Volumes are stored in part of the file system that is managed by Docker.

Bind mounts - Bind mounts can be stored anywhere in the host file system, and can by modified by any process including non-docker processes.

What is Docker Compose?

 FAQ

Docker Compose is a tool where you can define and share multi-container applications, by defining the application stack and services in a YAML file.

With a single Docker Compose command you can spin up the complete application stack, or tear it down.

 
Subscribe to our Questions

 

DevOps - Interview Questions

DevOps BasicsGITJenkinsJFrogDockerDocker SwarmKubernetes
 
RECOMMENDED RESOURCES
Behaviorial Interview
Top resource to prepare for behaviorial and situational interview questions.

STAR Interview Example