Interview Questions - Docker (50 Questions)
Interview Questions - Docker (50 Questions)
1. What is Docker?
Docker is a platform which packages an application and all its dependencies together in the form
of containers. This containerization aspect ensures that the application works in any
environment. Containerization - Docker Explained - Eureka’s you can see in the diagram, each
and every application runs on separate containers and has its own set of dependencies &
libraries. This makes sure that each application is independent of other applications, giving
developers surety that they can build applications that will not interfere with one another. So a
developer can build a container having different applications installed on it and give it to the QA
team. Then the QA team would only need to run the container to replicate the developer’s
environment. If you wish to learn more about Docker, then you can click here. Now, let me tell
you some more basic concepts of Docker, such as Docker file, images & containers. You can get
a better understanding with this Online Docker Certification Training Course.
Docker is a containerization platform that packages your application and all its dependencies
together in the form of a Docker container to ensure that your application works seamlessly in
any environment. Docker Container is a standardized unit which can be created on the fly to
deploy a particular application or environment. It could be an Ubuntu container, CentOS
container, etc. to full-fill the requirement from an operating system point of view. Also, it could
be an application oriented container like CakePHP container or a Tomcat-Ubuntu container etc.
A company needs to develop a Java Application. In order to do so the developer will setup an
environment with tomcat server installed in it. Once the application is developed, it needs to be
tested by the tester. Now the tester will again set up tomcat environment from the scratch to
test the application. Once the application testing is done, it will be deployed on the production
server. Again the production needs an environment with tomcat installed on it, so that it can host
the Java application. If you see the same tomcat environment setup is done thrice. There are
some issues that I have listed below with this approach:
Now, I will show you how Docker container can be used to prevent this loss. In this case, the
developer will create a tomcat Docker image (An Image is nothing but a blueprint to deploy
multiple containers of the same configurations) using a base image like Ubuntu, which is already
existing in Docker Hub (the Hub has some base images available for free). Now this image can be
used by the developer, the tester and the system admin to deploy the tomcat environment. This
is how this container solves the problem. I hope you are with me so far into the article. In case
you have any further doubts, please feel to leave a comment, I will be glad to help you. However,
now you would think that this can be done using Virtual Machines as well. However, there is
catch if you choose to use virtual machine. Let’s see a comparison between the two to
understand this better.
Let me take you through the above diagram. Virtual Machine and Docker Container are compared
on the following three parameters:
• Size – This parameter will compare Virtual Machine & Docker Container on their resource
they utilize.
• Start-up – This parameter will compare on the basis of their boot time.
• Integration – This parameter will compare on their ability to integrate with other tools with
ease.
I will follow the above order in which parameters are listed. So first parameter would be “Size”.
3. What is Virtualization?
Virtualization is the technique of importing a Guest operating system on top of a Host operating
system. This technique was a revelation at the beginning because it allowed developers to run
multiple operating systems in different virtual machines all running on the same host. This
eliminated the need for extra hardware resource. The advantages of Virtual Machines or
Virtualization are:
Virtual Machine Architecture - Docker Tutorial On Introduction to Docker – Eureka in the diagram
on the right, you can see there is a host operating system on which there are 3 guest operating
systems running which is nothing but the virtual machines. As you know nothing is perfect,
Virtualization also has some shortcomings. Running multiple Virtual Machines in the same host
operating system leads to performance degradation. This is because of the guest OS running on
top of the host OS, which will have its own kernel and set of libraries and dependencies. This
takes up a large chunk of system resources, i.e. hard disk, processor and especially RAM. Another
problem with Virtual Machines which uses virtualization is that it takes almost a minute to boot-
up. This is very critical in case of real-time applications.
These drawbacks led to the emergence of a new technique called Containerization. Now let me
tell you about Containerization.
4. What is Containerization?
Containerization is the technique of bringing virtualization to the operating system level. While
Virtualization brings abstraction to the hardware, Containerization brings abstraction to the
operating system. Do note that Containerization is also a type of Virtualization. Containerization
is however more efficient because there is no guest OS here and utilizes a host’s operating
system, share relevant libraries & resources as and when needed unlike virtual machines.
Application specific binaries and libraries of containers run on the host kernel, which makes
processing and execution very fast. Even booting-up a container takes only a fraction of a second.
Because all the containers share, host operating system and holds only the application related
binaries & libraries. They are lightweight and faster than Virtual Machines.
In the diagram on the right, you can see that there is a host operating system which is shared by
all the containers. Containers only contain application specific libraries which are separate for
each container and they are faster and do not waste any resources.
5. What is Docker?
A VM is a virtual server that emulates a hardware server. A virtual machine relies on the system’s
physical hardware to emulate the exact same environment in which you install your applications.
Depending on your use case, you can use a system virtual machine (that runs an entire OS as a
process, allowing you to substitute a real machine for a virtual machine), or process virtual
machines that let you execute computer applications alone in the virtual environment. Earlier,
we used to create virtual machines, and each VM had an OS which took a lot of space and made
it heavy.
Docker Swarm is a technique to create and maintain a cluster of Docker Engines. The Docker
engines can be hosted on different nodes, and these nodes which are in remote locations form a
Cluster when connected in Swarm mode.
For reasons mentioned already! Achieving high availability without any downtime is a priority for
every service provider out there. Will high availability impress your clients? Well, they won’t be
impressed if they face downtime. That is a no-brainer.
I still remember it correctly; I was working on a project. In that project we were following the
micro service architecture. For those of you who don’t know what is micro service, don’t worry I
will give you an introduction to it. The idea behind micro services is that certain types of
applications become easier to build and maintain when they are broken down into smaller,
compostable pieces which work together. Each component is developed separately, and the
application is then simply the sum of its constituent components.
In the above diagram there is an online shop with separate micro services for user-account,
product catalo, order processing and shopping carts. Well, this architecture has a lot of benefits:
• Even if one of your micro service fails, your entire application is largely unaffected.
• It is easier to manage
There are many other benefits as well, I won’t go into much detail about micro services in this
post. But, soon I will be coming up with a couple of blogs on micro services as well. In this
architecture, we were using CentOS Virtual Machines. Those Virtual Machines were configured
by writing long scripts. Well, configuring those VMs was not the only problem. Developing such
applications requires starting of several of micro services in one machine. So if you are starting
five of those services you require five VMs on that machine. Consider the diagram below:
The other problem is pretty common; I know a lot of you can relate to it. The application works
in a developer’s laptop but not in testing or production. This can be because of not keeping a
consistent.
There were many other problems apart from this as well, but I feel, these problems are enough
for me to explain you the need of Docker Containers.
Docker is a tool designed to make it easier to create, deploy and run applications by using
containers. You can create Docker Containers, these containers will contain all the binaries and
libraries required for your application or micro service in my case. So your application is present
in a container, or you have containerized your application. Now, that same container can be used
in the Test and Prod environment.
Docker Containers are a lightweight solution to Virtual Machines, and it uses the host OS. The
best part, you don’t have to pre-allocate any RAM to the Docker Container, it will take it as and
when required. So, with Docker Container I don’t have to worry about wastage of resources.
Now I will take you through Docker Engine which is the heart of the system.
Docker Engine is simply the application that is installed on your host machine. It works like a
client-server application which uses:
As per the above image, in a Linux Operating system, there is a client which can be accessed from
the terminal and a Host which runs the Daemon. We build our images and run containers by
passing commands from the CLI client to the Daemon. However, in case of Windows/Mac there
is an additional Toolbox component inside the Docker host. This Docker Toolbox is an installer to
quickly and easily install and setup a Docker environment on your Windows/iOS. This Toolbox
installs Docker Client, Machine, Compose (Mac only), Kinematic and Virtual Box. Let’s now
understand three important terms, i.e. Docker Images, Docker Containers and Docker Registry.
Docker Image can be compared to a template which is used to create Docker Containers. They
are the building blocks of a Docker Container. These Docker Images are created using the build
command. These Read only templates are used for creating containers by using the run
command. We will explore Docker commands in depth in the “Docker Commands blog”.
Docker lets people (or companies) create and share software through Docker images. Also, you
don’t have to worry about whether your computer can run the software in a Docker image — a
Docker container can always run it. I can either use a ready-made Docker image from Docker-
hub or create a new image as per my requirement. In the Docker Commands blog we will see
how to create your own image.
Docker Containers are the ready applications created from Docker Images. Or you can say they
are running instances of the Images and they hold the entire package needed to run the
application. This happens to be the ultimate utility of the technology.
Finally, Docker Registry is where the Docker Images are stored. The Registry can be either a user’s
local repository or a public repository like a Docker Hub allowing multiple users to collaborate in
building an application. Even with multiple teams within the same organization can exchange or
share containers by uploading them to the Docker Hub, which is a cloud repository similar to
GitHub.
17. What is Docker and what are the benefits of using it?
Docker is a containerization platform that packages applications into standardized units called
containers. Benefits include portability across machines, lightweight with less resource usage
than VMs, faster start times, and easier scaling & maintenance of apps.
Containers are lightweight, standalone, executable packages of software that include application
code, runtimes, dependencies, and configurations that can run quickly and reliably from one
computing environment to another.
Docker containers share the host OS kernel and run as isolated processes making them more
lightweight and efficient unlike VMs which need full guest OSes. This allows faster start times and
lower resource usage for Docker.
Docker images are read-only templates used for creating container instances. Images are made
up of file system changes and configuration instructions used to deploy containers. Images
become containers when they run on the Docker engine.
Containers are runtime instances of Docker images launched by the Docker engine. They are
isolated application platforms that bundle code and dependencies to run the application on host
OS sharing the kernel.
Docker Hub is a cloud-based registry service for hosting Docker images. It provides capabilities to
upload/download, store and share Docker images with teams and allows integration with Docker
CLI to simplify pulling images for container launches.
Docker engine, Docker Desktop (Mac/Windows) and Docker Compose can be used to run Docker
containers on local dev and test machines for building applications.
Docker supports all Linux distributions and versions later than 3.10 kernel. It also runs on macros
and Windows 10 using its native hypervisor technologies. ARM and IBM systems architectures
are also supported.
A Docker file is a text file that contains instructions for building Docker images automatically using
simple commands. It simplifies maintenance allowing image sources to be tracked and
customized for specific environments.
By attaching a host directory or an anonymous volume container to the container’s image using
the Docker run -v option during launch of container. Data gets persisted in volumes even if
container is removed.
The docker network command allows configuring networks for communication between
containers launched within an isolated Docker network. Containers can be attached to multiple
networks like bridge, overlay, macula etc. based on app needs.
Through namespace isolation of containers from host and between containers, restricting
privileges of containers using capabilities, network policies, file system permissions and
deploying images scanned for vulnerabilities into trusted registries after sign & verification.
A Docker registry is a repository for storing, managing and distributing Docker images. Docker
Hub is a public example while enterprises often host private registries to maintain development
pipelines across environments and control image access.
Using tools like Docker Compose for local development, Docker Swarm for cluster management
and popular CI/CD frameworks like Jenkins, Circles etc. to set up deployment pipelines -
promoting images to higher environments.
Docker Compose is a tool for defining and running multi-container Docker applications by using
a YAML configuration file for orchestrating the application services dependency and networking.
This allows automated one-click environment setups.
AWS ECS, Azure Container Instances, Google Kubernetes Engine and IBM Cloud Kubernetes
Service allow organizations to run Docker zed applications without having to self-manage the
infrastructure. They offer scalable, highly-available container hosting platforms.
Using Docker APIs and CLI commands for basic monitoring. For advanced monitoring, metrics and
logging solutions like Prometheus, Granma, cad visor, Elastic Stack etc. allow gathering
operational insights on container health, app performance, resource usage and logs.
A Docker image registry is a storage and content delivery system holding named Docker images,
available in different tagged versions, that are pulled for container launches based on
requirement. Popular registries are public like Docker Hub or private like AWS ECR.
Containers can be attached to virtual bridge networks that route traffic between containers
internally based on IP addresses and expose ports externally to allow ingress traffic from outside
based on mappings defined at runtime.
36. What are the popular storage drivers for the Docker engine?
Overlays, AUFS, ZFS, Bars, Device Mapper are some of the widely used Docker storage drivers.
Overlay2 and AUFS see maximum adoption currently for union file system capabilities layering
image fs over host fs.
By using shared data volumes that allow detachable/reattach able data directories used by
containers identified by volume names allowing portability of tasteful data across environments
between app upgrades.
Docker Swarm provides native clustering capabilities to turn a group of Docker engines
participating as nodes into a single virtual Docker engine for easier scaling and maintenance of a
distributed application. Enables natively deploying containers across a pool of nodes.
Docker Swarm, Kubernetes and Apache Mesas are popular container orchestration technologies
that help manage clusters of Docker hosts as a single deployment target supporting replication,
scaling, networking, security etc.
A Docker repository refers to a hosted registry codebase containing Docker images organized by
families i.e. suites of images identified by names which denote applications/middleware software
releases tagged by versions.
41. How does one control CPU and memory resources for containers?
By limiting container access to a defined percentage of total host resources using the -m and -
cpuset-cpus flags with Docker run to restrict memory usage and assign specific CPUs.
Using Docker run --rm instructs Docker engine to delete containers immediately after they stop
executing allowing removal of stale temporary containers that are no longer active and not
required.
43. What interface helps applications use Docker containers without knowing specifics?
Docker Engine SDK allows applications to make calls to control Docker via simple APIs rather than
CLI/tool specifics. Libraries are available for popular languages allowing app portability across
environments.
Unions allows overlaying multiple directories transparently into cohesive file system providing
single merged view across layers forming image via efficient copy-on-write model rather than
duplicating files.
Building containers with app runtimes & libraries needed bundled inside isolated containers
makes running apps with dependencies easier without worrying about external environment
differences across deployments.
Entry point allows specifying a default executable for running containers as command overrides
when launched. If not overridden, entry point gets invoked allowing standardization of runtime
behaviours without altering base images.
Docker zing apps refers to packaging, distributing apps and dependencies into standardized
images that can run as isolated, portable containers consistently across environments -
simplifying maintenance and coordination.
49. What are the popular monitoring solutions for Docker deployments?
cad visor, Prometheus, Granma provide insights into resource usage and performance metrics of
Docker engines and containers. Additional logging tools are required for gathering application
logs from containers.
50. How can security vulnerabilities be minimized for Docker containers in devils pipelines?
By following guidelines on creating optimized base images free of additional packages, fixing
packages with only latest security patches, and scanning container images in pipelines before
deploying to higher environments.