Docker Interview Questions Answers
Docker Interview Questions Answers
in
Containers allow a developer to package up an application with all of the parts it needs,
such as libraries and other dependencies and ship it all out as one package.
By doing so, the developer can rest assured that the application will run on any other Linux
machine regardless of any customized settings that machine might have that could differ
from the machine used for writing and testing the code. In a way, Docker is a bit like a
virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating
system. Docker allows applications to use the same Linux kernel as the system that they're
running on and only requires applications be shipped with things not already running on the
host computer. This gives a significant performance boost and reduces the size of the
application.
And they are designed to make it easier to provide a consistent experience as developers
and system administrators move code from development environments into production in a
fast and replicable way.
For developers, it means that they can focus on writing code without worrying about
www.qaautomation.co.in
www.qaautomation.co.in
It also allows them to get a head start by using one of thousands of programs already
designed to run in a Docker container as a part of their application.
For operations staff, Docker gives flexibility and potentially reduces the number of systems
needed because of its small footprint and lower overhead.
Docker containers are not tied to any specific infrastructure: they run on any computer, on
any infrastructure, and in any cloud.
Now explain how to create a Docker container, Docker containers can be created by either
creating a Docker image and then running it or you can use Docker images that are present
on the Dockerhub. Docker containers are basically runtime instances of Docker images.
Images are stored in a Docker registry such as registry.hub.docker.com because they can
become quite large, images are designed to be composed of layers of other images,
allowing a minimal amount of data to be sent when transferring images over the network.
www.qaautomation.co.in
www.qaautomation.co.in
It provides a centralized resource for container image discovery, distribution and change
management, user and team collaboration, and workflow automation throughout the
development pipeline.
➢ Once the Dockerfile is created, you build it to create the image of the container. The
image is just the "compiled version" of the "source code" which is the Dockerfile.
➢ Once you have the image of the container, you should redistribute it using the registry.
The registry is like a git repository -- you can push and pull images.
➢ Next, you can use the image to run containers. A running container is very similar, in
many aspects, to a virtual machine (but without the hypervisor).
Using docker build users can create an automated build that executes several commandline
instructions in succession.
Answer :
Docker containers are easy to deploy in a cloud. It can get more applications running on the
same hardware than other technologies.
This command will create and start a container. You should also add, If you want to check
the list of all running container with the status on a host use the below command:
docker ps -a
www.qaautomation.co.in
www.qaautomation.co.in
That’s because it’s more transparent than ADD. COPY only supports the basic copying of local
files into the container, while ADD has some features (like local-only tar extraction and
remote URL support) that are not immediately obvious. Consequently, the best use for ADD is
local tar file auto-extraction into the image, as in ADD rootfs.tar.xz /.
Answer :
Docker runs on only Linux and Cloud platforms and below are the vendors of Linux:
Cloud:
❖ Amazon EC2
❖ Google Compute Engine
❖ Microsoft Azure
❖ Rackspace
FROM: We use FROM to set the base image for subsequent instructions. In every valid
Dockerfile, FROM is the first instruction.
LABEL: We use LABEL to organize our images as per project, module, licensing etc. We can
also use LABEL to help in automation.
In LABEL we specify a key value pair that can be later used for programmatically handling the
Dockerfile.
RUN: We use RUN command to execute any instructions in a new layer on top of the current
image. With each RUN command we add something on top of the image and use it in
subsequent steps in Dockerfile.
www.qaautomation.co.in
www.qaautomation.co.in
Docker stats: When we call docker stats with a container id, we get the CPU, memory usage
etc of a container. It is similar to top command in Linux.
Docker events: Docker events are a command to see the stream of activities that are going
on in Docker daemon.
Some of the common Docker events are: attach, commit, die, detach, rename, destroy etc.
We can also use various options to limit or filter the events that we are interested in.
If you would like your container to run the same executable every time, then you should
consider using ENTRYPOINT in combination with CMD.
As far as the number of containers that can be run, this really depends on your
environment. The size of your applications as well as the amount of available resources will
all affect the number of containers that can be run in your environment.
Containers unfortunately are not magical. They can’t create new CPU from scratch. They
do, however, provide a more efficient way of utilizing your resources.
It provides a centralized resource for container image discovery, distribution and change
management, user and team collaboration, and workflow automation throughout the
development pipeline.
www.qaautomation.co.in