Thursday, 26 December 2019

Top 20 Docker Interview Questions



Ques: 1. What do you understand by Docker?
 
Ans: 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.


Ques: 2. What is Docker image?

Ans: The Docker image help to create Docker containers. You can create the Docker image with the build command. Due to this, it creates a container that starts when it begins to run. Every docker images are stored in the Docker registry.


Ques: 3. What is Virtualization?

Ans: 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 x86 based system.


Ques: 4. Can you explain the process of scaling your Docker containers?
 
Ans: 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.


Ques: 5. What is CNM?

Ans: 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.


Ques: 6. Can you explain the Docker Trusted Registry?

Ans: 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.


Ques: 7. How do I run multiple copies of Compose file on the same host?

Ans: 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.


Ques: 8. What is Hypervisor?

Ans: A hypervisor is a software that makes virtualization possible. It is also called Virtual Machine Monitor. It divides the host system and allocates the resources to each divided virtual environment. You can basically have multiple OS on a single host system. There are two types of Hypervisors:

Type 1: It’s also called Native Hypervisor or Bare metal Hypervisor. It runs directly on the underlying host system. It has direct access to your host’s system hardware and hence does not require a base server operating system.

Type 2: This kind of hypervisor makes use of the underlying host operating system. It’s also called Hosted Hypervisor.


Ques: 9. What is containerization?

Ans:In the software development process, code developed on one machine might not work perfectly fine on any other machine because of the dependencies. This problem was solved by the containerization concept. 

So basically, an application that is being developed and deployed is bundled and wrapped together with all its configuration files and dependencies. This bundle is called a container. Now when you wish to run the application on another system, the container is deployed which will give a bug-free environment as all the dependencies and libraries are wrapped together. Most famous containerization environments are Docker and Kubernetes.


Ques: 10. What is the difference between virtualization and containerization?

Ans: Once you’ve explained containerization and virtualization, the next expected question would be differences. The question could either be differences between virtualization and containerization or differences between virtual machines and containers. Either way, this is how you respond.

Containers provide an isolated environment for running the application. The entire user space is explicitly dedicated to the application. Any changes made inside the container is never reflected on the host or even other containers running on the same host. Containers are an abstraction of the application layer. Each container is a different application.

Whereas in Virtualization, hypervisors provide an entire virtual machine to the guest(including Kernal). Virtual machines are an abstraction of the hardware layer. Each VM is a physical machine.


Ques: 11. Explain Docker Architecture?

Ans: 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.

  
Ques: 12. What is a Dockerfile?

Ans: 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.


Ques: 13. What is the life cycle of a Docker Container?
Ans: This is one of the most popular questions asked in Docker interviews. Docker containers have the following life cycle:

  • 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


Ques: 14. How do you scale your Docker containers?
Ans: Docker containers can be scaled to any level, starting from a few hundreds to even thousands or millions of containers. The only condition is that the containers need the memory and the OS all the time, and there should not be a constraint on these when the Docker is getting scaled.


Ques: 15. What is the difference between the COPY and ADD commands in a Dockerfile?

Ans: Although ADD and COPY are functionally similar, generally speaking, COPY is preferred. 

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


Ques: 16. What are the most common instructions in Dockerfile?

Ans: Some of the common instructions in Dockerfile are as follows:

  • 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. 
  • CMD: We use CMD command to provide default values of an executing container. In a Dockerfile, if we include multiple CMD commands, then only the last instruction is used.


Ques: 17. Can you explain the basic Docker usage workflow?

Ans:
  1. Everything starts with the Dockerfile. The Dockerfile is the source code of the Image. 
  2. 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. 
  3. 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. 
  4. 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).

 
Ques: 18. What are some similarities between Virtual Machine & Docker ?

Ans: Docker is not just like a Virtual Machine. It uses the host kernel & can’t boot a different operating system. So 5 similarities between Docker & VIrtual Machine can be:

Virtual Machine
Docker
Process in on VM cant see processes in other VMs
Process in one container cant see processes in other container
Each VM has its own root filesystem

Each container has its own root file system (Not Kernal)

Each VM gets its own virtual network adapter

Docker can get virtual network adapter. It can have  separate IP and ports

VM is a running instance of physical files(.VMS and .VMDK)

Docker containers are running instances of Docker Image

Host OS can be difference from guest OS

Host OS can be different from Container OS


Ques: 19. What are some of the differences between Docker container & Virtual Machine?

Ans: The differences between docker container and virtual machines are following:

Virtual Machine

Docker
Each Virtual Machine runs its own OS.

All containers share the same kernel of the host.
Boot up time is in minutes.
Containers instantiate in seconds.
Virtual Machines snapshots are used sparingly.

Images are build incrementally on top of another like layers. Lots operating system images/snapshots.
Not effective diffs.Not version controlled.

Images can be diffed and can be version controlled.Dockerhub is like GITHUB.

Cannot run more than couple of VMs on an average laptop.
Can run many Docker containers in a laptop.

Only one VM can be started from one set of VMx and VMDK files.

Multiple Docker containers can be started from one Docker image.



Ques: 20. Can I use JSON instead of YAML for my Docker Compose file? 

Ans: Yes. YAML is a superset of json so any JSON file should be valid YAML. To use a JSON file with Compose, specify the filename to use, for example:
 
 docker-compose -f docker-compose.json up


You can use json instead of YAML for your compose file, to use json file with compose, specify the filename to use.






No comments:

Post a Comment