Docker Interview Questions and Answers for Experienced and Freshers

1. Can you explain how Docker is advantageous over Hypervisors?
Docker is advantageous in the below ways
1. It is lightweight.
2. More efficient in terms of resources.
3. It uses very fewer resources and also the underlying host kernel rather than developing its hypervisor.

2. On what all platforms does Docker run?
Docker will run on various platforms as follows:
a. Linux
b. Ubuntu 12.04, 13.04 et al
c. Fedora 19/20+
d. RHEL 6.5+
e. CentOS 6+
f. Gentoo
g. ArchLinuxopenSUSE 12.3+
h. CRUX 3.0+
i. Microsoft Windows
j. Windows Server 2016
k. Windows 10
l. Cloud
m. Amazon EC2
n. Google Compute Engine
o. Microsoft Azure
p. Rackspace

3. What is the main advantages of implementation of Docker?
The most important advantages to a Docker-based architecture is actually standardization. Docker will provide repeatable development, build, test, and production environments. Every team member can work on a production parity environment by Standardizing service infrastructure across the entire pipeline.

4. What are the different ways that you can download Docker?
You can download in the following ways:
a. Install Docker for Mac
b. run it
c. Double-click Docker.dmg for openning the installer, then drag Moby the whale to the Applications folder.
d. Double-click Docker.app in the Applications folder to start Docker.
e. Click the whale ( ) to get Preferences and other options.
f. Select About Docker to verify that you have the latest version.

5. Briefly explain the difference between virtualization and containerization?
Containers will provide an isolated environment to run the application. The entire user space will be explicitly dedicated to the application. Any changes which are made inside the container will never reflected on the host or even other containers running on the same host. Containers will be an abstraction of the application layer. Each container has a different application. In virtualization, hypervisors will provide an entire virtual machine to the guest including Kernal. Virtual machines will be an abstraction of the hardware layer. Each VM is a physical machine.

6. Briefly explain Docker Architecture?
Docker Architecture will consist of a Docker Engine that is a client-server application:
1. A server which is a type of long-running program which is called a daemon process ( the docker command ).
2. A REST API which will specify interfaces that programs will use to talk the daemon and instruct it what to do.
3. A command-line interface (CLI) client (the docker command) The CLI will use the Docker REST API to control or interact with Docker daemon applications use the underlying API and CLI.

7. What is the command to run the image as a container?

$ sudo docker run -i -t alpine /bin/bash

8. Can you explain how is Docker better than other tools that use containers?
Docker will utilize the cloud to run its container-related operations – which is not used by many other development tools. Docker will become much more flexible and adaptable to different scenarios using the cloud, which might come up during the development or shipment processes. This is the main reason to use the Docker when compared to other container-based developer tools.

9. How far do Docker containers scale?
The Web deployments such as Google, Twitter and best examples in the Platform Providers such as Heroku, dotCloud run on Docker that can scale from the ranges of hundreds of thousands to millions of containers running in parallel, provided the condition which the OS and the memory will not run out from the hosts which runs all these innumerable containers hosting your applications.

10. Explain the advantage of Docker over hypervisors?
Docker is lightweight and more efficient in resource uses because it will use the underlying host kernel rather than creating its hypervisor.

11. How is Docker different from other container technologies?
Docker is a quite fresh project. It was created in the Era of Cloud, Therefore a lot of things are better than in other container technologies. Following are the features which are good in Docker:
1. Docker will run on any infrastructure, we can run docker on laptop, or can run it in the cloud.
2. Docker has a Container HUB which is a repository of containers that can download and use. We can even share containers with any applications.
3. 3. Docker is quite well documented.

12. How is Docker different from other container technologies?
Docker is a quite fresh project. It was created in the Era of Cloud, Therefore a lot of things are better than in other container technologies. Following are the features which are good in Docker:
a. Docker will run on any infrastructure, we can run docker on laptop, or can run it in the cloud.
b. Docker has a Container HUB which is a repository of containers that can download and use. We can even share containers with any applications.
c. Docker is quite well documented.

13. Do you think open source development has heavily influenced cloud technology development?
I think open source software will be closely tied to cloud computing. Both in terms of the software running in the cloud and the development models which have enabled the cloud. Open source software will be cheap, it’s low friction both from an efficiency and a licensing perspective.

14. Explain Docker Hub?
Docker Hub can be considered as a cloud registry which lets us link the code repositories, create the images, and test them. We will also store our pushed images, or we will link to the Docker Cloud, therefore that the images will be deployed to the host. We have a centralized container image discovery resource which will be used for the collaboration of our teams, automating the workflow and distribution, and changing management by creating the development pipeline.

15. Explain benefit of Dockerizing?
Dockerizing enterprise environments will help teams to leverage over the Docker containers to form a service platform such as a CaaS (Container as a Service). It will provide teams that necessary agility, portability and also lets them control staying within their own network / environment. Most of the developers opt for using Docker and Docker alone because of the flexibility and also the
ability that it will provide to quickly build and ship applications to the rest of the world. Docker containers will be portable and these will run on any environment without making any additional changes when the application developers will have to move between Developer, Staging and Production environments. This whole process will be seamlessly implemented without the need of performing any recoding activities for any of the environments. These not only will help to reduce the time between these lifecycle states, but also will ensure that the whole process can be performed with utmost efficiency. There is every possibility for the Developers for debugging any certain issue, fix it and will also update the application with it and propagate this fix to the higher environments with utmost ease. The operations teams will handle the security of the environments while also allow the developers build and ship the applications in an independent manner. The CaaS platform which is provided by Docker framework will deploy on-premise and can also loaded with full of enterprise level security features like role-based access control, integration with LDAP or any Active Directory, image signing and etc.Operations teams will have heavily rely on the scalability provided by Docker and will also leverage over the Dockerized applications across any environments. Docker containers will be so portable that it will allow teams to migrate workloads which will run on an Amazon’s AWS environment to Microsoft Azure without change its code and also with no downtime at all. Docker will allow teams to migrate these workloads from their cloud environments to their physical datacenters and vice versa. This also will enable the Organizations to focus on the infrastructure from the gained advantages both monetarily and also the self-reliability over Docker. The lightweight nature of Docker containers are compared to traditional tools such as virtualization, combined with the ability for Docker containers to run within VMs, allowing teams for optimizing their infrastructure by 20X, and save money in the process.

16. Difference between Docker Image and container?
Docker container is the runtime instance of docker image. Docker Image can not have a state and its state never changes because it will be just set of files whereas docker container will have its execution state.

17. What are the common instruction in Dockerfile?
The common instruction in Dockerfile are FROM, LABEL, RUN, and CMD.

18. What is memory-swap flag?
Memory-swap is a modified flag which has meaning if- memory is set. Swap will allow the container to write express memory requirements on disk when the container has exhausted all the RAM
which is available to it.

19. Explain Docker Swarm?
Docker Swarm is native gathering for docker which can help to a group of Docker hosts into a single and virtual docker host. It will offer the standard docker application program interface.

20. How can you monitor the docker in production environments?
Docker states and Docker Events can be used for monitoring docker in the production environment.

21. What are the steps for the Docker container life cycle?
Following are the steps for Docker life cycle:
1. Build
2. Pull
3. Run

22. How can you run multiple containers using a single service?
By using docker-compose, we can run multiple containers using a single service. All dockercompose files can use yaml language.

23. What is CNM?
CNM will stand for Container Networking Model. It will form the basis of container networking in a Docker environment. This docker’s approach will provide container networking with support for multiple network drivers.

24. Does Docker offer support for IPV6?
Yes, Docker will provide support IPv6. IPv6 networking is supported only on Docker daemons which will run on Linux hosts. However, if we want to enable IPv6 support in the Docker daemon, we
required to modify /etc/docker/daemon.json and set the ipv6 key to true.

25. Explain the different methods for creating a Docker container?
We will use any of the specific Docker images to create a Docker container using the below command.
docker run -t -i command name
This command not will create the container but also start it.

26. What is the best place to find decent examples of ‘compose files’ ?
Most of the high-key companies which require Docker experts use a specific tool to manage their internal workings. That tool is called GitHub.
Other than all of the main functions which it will perform, it is also a great place to find the beforementioned compose files for Docker containers.

27. How do you think Docker will change virtualization and cloud environments?
There are a lot of workloads which Docker is ideal for. Both in the hyper-scale world of many containers and in the dev-test-build use case. I will fully expect a lot of companies and vendors to
embrace Docker as an alternative form of virtualization on both bare metal and in the cloud.

28. Briefly explain what is Docker and why we use docker
Docker is an open-source container service designed to facilitate applications deployment inside the software containers. It will rely on Linux Kernel Features like namespaces and cgroups ensuring which resource isolation and application packaging along with its dependencies. Docker was licensed under Apache License 2.0 in the binary form and fully written in the Go programming language. It can support several operating systems like Linux, Cloud, Windows, and Mac OS and different platforms like ARM architecture and x86-64 windows platforms.2. Why use Docker? We use docker as
a. A user can quickly build, ship, and run its applications.
b. A single operating system kernel will run all containers.
c. Docker container is more light-weight than the virtual machines.
d. A user will deploy Docker containers anywhere, on any physical and virtual machines and even on the cloud.

29. What are the most used commands of Docker.
a. ps lists the running containers.
b. dockerd launches Docker Daemon.
c. build is used to build an image from a DockerFile.
d. create is used to create a new image form container’s changes.
e. pull is used to download a specific image or a repository.
f. run is used to run a container.
g. logs display the logs of a container.
h. rm removes one or more containers.
i.rmi removes one or more images.
j. stop is used to stop one or more container.
k. kill is used to kill all running containers.

30. Explain the Lifecycle of Docker container?
The Lifecycle of Docker Container with CLI is as following:
a. Create a Container.
b. Run the created Container.
c. Pause the processes running inside the Container.
d. Unpause the processes running inside the Container.
e. Start the Container, if exists in a stopped state.
f. Stop the Container as well as the running processes.
g. Restart the Container as well as the running processes.
h. Kill the running Container.
i. Destroy the Container, only if it exists in a stopped state.

31. What are the things that you can you do with Docker?
We are just some of the use cases which will provide a consistent environment at low overhead with the enabling technology of Docker.
1. Simplifying Configuration.
2. Code Pipeline Management.
3. Developer Productivity.4. App Isolation.
5. Server Consolidation.
6. Debugging Capabilities.
7. Multi-tenancy.

32. Will docket Benefits for Microservices ?
Docker will Benefits for Microservices. Docker, as a containerization tool, will be often compared to virtual machines. Virtual machines are introduced to optimize the use of computing resources. We will run several VMs on a single server and deploy each application instance on a separate virtual machine.

33. What is a Docker Container and its advantages ?
Docker containers will include the application and all of its dependencies. It will share the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers will not required any specific infrastructure, they will run on any infrastructure, and in any cloud. Docker containers will be basically runtime instances of Docker images.
Following are major advantage of using Docker Container:-
a. It will offer an efficient and easy initial set up.
b. It will allow to describe application lifecycle in detail.
c. Simple configuration and interacts with Docker Compose.
d. Documentation will provide every bit of information.

34. What is Docker Compose  ?
Docker Compose is a YAML file which will contain details about the service, network, and volumes to set up the Docker application. Therefore, we will use Docker compose for creating separate
containers, host them and get them to communicate with other containers.

35. Explain is Docker Swarm ?
Docker Swarm is native clustering for Docker. It will turn a pool of Docker hosts into a single, virtual Docker host. Docker Swarm will serve the standard Docker API, any tool which already communicates with a Docker daemon will be use Swarm to transparently scale to multiple hosts.

36. What is Docker Engine?
Docker daemon or Docker engine will represent the server. The docker daemon and the clients will run on the same or remote host, which will communicate through command-line client binary and full RESTful API.

37. Explain how do you run multiple copies of Compose file on the same host?
Compose will use the project name which will allow us for creating 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.

38. Explain the most important requirement for building a Docker container?
The most important requirement for building a container with Docker is the default image. This default image will vary depending on the code that we are using. To find out and access the default
image, we should go to the Docker Hub and search for the specific domain that we required. After we find the image, all that’s left to do is deal with the documentation and that’s it – we can create a Docker container.

39. Explain how is Docker different from Hypervisor?
Hypervisor will require to have extensive hardware to function properly, while Docker will run on the actual operating system. This will allow Docker to be exceptionally fast and perform tasks in a fluid manner – something which Hypervisor tends to lack.63.Can I use JSON instead of YAML for my compose file in Docker? YES, We can very comfortably use JSON instead of the default YAML for Docker compose file. In order to use JSON file with compose, we required to specify the filename to use as the following:
docker-compose -f docker-compose.json up

40. Explain the process to create Docker container?
We will create a Docker container out of any specific Docker image of choice and the same can be achieved using the command given below.
docker run -t -i command name
The command above can create the container . In order to check whether the Docker container will be created and whether it is running or not, we could make use of the following command. This command can list out all the Docker containers along with its statuses on the host that the Docker container runs.
docker ps –a

41. What are the networks that are available by default?
bridge It is the default network all containers connect to if we will not specify the network. none connects to a container-specific network stack which will lack a network interface host connects to the host’s network stack – there will be no isolation between the host machine and the container, as far as network is concerned.

42. What is the main thing that you find usefull in Docker ?
Docker is fast, easy for using and a developer-centric DevOps-ish tool. it is easy to package and ship code. Developers will want tools which abstract away a lot of the details of that process. They will just want for seeing their code working. That will lead to all sorts of conflicts with Sys Admins when code will be shipped around and turns out not to work somewhere other than the developer’s environment. Docker will turn to work around that by making code as portable as possible and making that portability user-friendly and simple.

43. What are the commonly used Docker Commands?
Command : Description
Dockerd : Launch the Docker DaemonInfo Displays information System-Wide
Version : Displays the Docker Version information
Build : Builds images for Docker files
Inspect : Returns low-level information on an image or container
History : Shows Image History
Commit : Creates new images from Container changes
Attach : Attaches to a running container
Load : Load an image from STDIN or tar archive
Create : Create a new container
Diff : Inspect changes on a container’s file system
Kill : Kill a running container

44. What are the common case why services take 10 seconds to recreate or stop?
Docker compose stop attempts to stop a specific Docker container by sending a SIGTERM message. Once this message will be delivered, it CaaS wait for the default timeout period of 10 seconds
and once the timeout period will be crossed, it will then send out a SIGKILL message for the container – in order to kill it forcefully. If we are actually waiting for the timeout period, then it will mean that the containers will not shutting down on receiving SIGTERM signals / messages. In an attempt to solve this issue, the following is what we will do:
1. We can ensure that we are using the JSON form of the CMD and also the ENTRYPOINT in dockerfile.
2. Use [“program”, “argument1”, “argument2”] instead of sending it as a plain string as like this “program argument1 argument2”.
3. Using the string form, which will make Docker run the process using bash which will not handle signals properly. Compose always uses the JSON form.
4. If it is possible then modify the application which we are intended to run by adding an explicit signal handler for the SIGTERM signal
5. Also set the stop_signal to a proper signal which the application will understand and also know how to handle it.

45. How many containers can run per host?
Depending on the environment where Docker hosts the containers, there will be as many containers as the environment will support. The application size, available resources such as CPU, memory will decide on the number of containers which will run on an environment. Though containers will create newer CPU on their own but they will definitely provide efficient ways of utilizing the resources. The containers themselves are super lightweight and will only last as long as the process they are running.

46. Explain the differences between the ‘docker run’ and the ‘docker create’?
The most important difference is that by using the ‘docker create’ command we will create a Docker container in the Stopped state. We will also give it with an ID which can be stored for later
usages as well. This will be achieved by using the command ‘docker run’ with the option –cidfile FILE_NAME as like this:
‘docker run –cidfile FILE_NAME’

47. What are Registries in docker ?
There are following types of registry :
1. Public Registry
2. Private Registry
Docker’s public registry is called Docker hub, which can allow to store images privately. In Docker hub, we can store millions of images.

48. What are the different states of Docker container?
Following are the common states of Docker container
1. Running
2. Paused
3. Restarting
4. Exited

49. What is the command to control Docker with System?
systemctl start/stop docker
service docker start/stop.

50. What is Docker Trusted Registry?
Docker Trusted Registry is the enterprise-grade image storage toll for Docker. We should install it after firewall so that we can securely manage the Docker images we will use in the applications.

51. What are the various states that a Docker container can be in at any given point in time?
There will be four states which a Docker container will be in, at any provided point in time. Those states will be as given as follows:
Running
Paused
Restarting
Exited

52. How can you remove a paused container from Docker?
It is not possible for removing a container from Docker which is just paused. It is a must which a container will be in the stopped state, before it will be removed from the Docker container.

53. Can you give some of the main drawbacks of Docker?
a. Not provide a storage option
b. Provides a poor monitoring option.
c. No automatic rescheduling of inactive Nodes
d. Complicated automatic horizontal scaling set up

54. Explain the preferred way of removing containers – ‘docker rm -f’ or ‘docker stop’ then followed by a ‘docker rm’?
The best and the preferred way for removing containers from Docker is to use the ‘docker stop’, as it will allow sending a SIG_HUP signal to its recipients providing them the time which is required for performing all the finalization and cleanup tasks. Once this activity can be completed, we will then comfortably remove the container using the ‘docker rm’ command from Docker and thereby updating the docker registry as well.

55. What command should you run to see all running container in Docker?
$ docker ps

56. What is the default location where the docker volumes are stored?
/var/lib/docker/volumes

57. How to use JSON instead of YAML compose file?
docker-compose -f docker-compose.json up

58. How to include code with copy/add or volumes?
In docker file, we required to use COPY or ADD directive. This is useful to relocate code. However, we should use a volume if we want to make changes.

59. Explain Docker Namespaces?
The Namespace in Docker is a technique that will offer isolated workspaces called the Container. Namespaces can also offer a layer of isolation for the Docker containers.

60. In Docker what’s the difference between up, run, and start?
On any given scenario, we will always want docker-compose up. Using the command UP, we will start or restart all the services which are defined in a docker-compose.yml file. In the “attached” mode, that will also the default mode – we will be able to see all the log files from all the containers. In the “detached” mode, it can exit after starting all the containers that will continue to run in the background showing nothing over in the foreground. Using docker-compose run command; we can be able to run the one-off or the ad-hoc tasks which will be required to be run as per the Business needs and requirements. This will require the service name to be provided which we would want to run and based on that, it can only start those containers for the services which the running service will depend on. Using the run command, we can run tests or perform any of the administrative tasks as like removing / adding data to the data volume container. It will also very similar to the docker run –ti command that opens up an interactive terminal to the containers an exit status which will matche with the exit status of the process in the container.
Using the docker-compose start command; we will only restart the containers which were previouslycreated and were stopped. This command will never create any new Docker containers on its own.

61. Explain the important features of Docker?
a. Easy Modeling
b. version Control
c. Placement/Affinity
d. Application Agility
e. Developer Productivity
f. Operational Efficiencies

62. Drawbacks of Docker?
a. It will not provide a storage option.
b. Offer a poor monitoring option.
c. No automatic rescheduling of inactive Nodes.
d. Complicated automatic horizontal scaling set up.

63. What are Docker images?
A Docker image is a file which is comprised of multiple layers, used for executing code in a Docker container. An image will be essentially built from the instructions for a complete and executable version of an application, which will relies on the host OS kernel.

64. What is Docker Hub?
Docker hub is a cloud-based registry that will help us to link code repositories. It will allows us to build, test, store image in the Docker cloud. We can deploy the image to host with the help of the Docker hub.

65. What are Registries in docker ?
Two types of registry are
1. Public Registry
2. Private Registry
Docker’s public registry is called Docker hub, which will allow to store images privately. In Docker hub, we will store millions of images.

66. Explain Docker object labels.
Docker object labels is a method to apply metadata to docker objects which will include images, containers, volumes, network, swarm nodes, and services.

67. How to create a Docker container?
A Docker Container will be created by running any specific Docker image.
To create a container use as below
docker run -t -i command name
If to verify that whether the container has created or whether that is running or not, use the following command as this command will lists out all the running Docker containers on the host along with their status.
docker ps -a

68. Explain the components of Docker Architecture?
Docker Client (docker): It will enable a user for Docker interaction. It will communicate with more than one Docker Daemon. It can use Docker API and can send command ( docker run) to Docker Daemon ( dockerd ) which carries them out.
Docker Daemon ( dockerd ) : It will give a complete environment to execute and run applications. It is consists of images, containers, volumes and responsible for all container-related actions. It can pull and create the container images as what the client requests. A Daemon will communicate with other daemons for its service management.
Docker registry : This is the versioning, storage, and distribution system for Docker images. It allows Docker users to pull images locally, and push new images to the registry. Docker Hub is a public registry instance of
Docker used by default while installing Docker Engine.
Docker Image : This is a lightweight, standalone, executable package of Docker stored in a Docker Registry. It can be used for creating a container. It will consist of everything required to run an application- code, a runtime, system libraries, system tools, environment variables, configuring files, and settings.
Docker Container : It is a standardized unit of software used for deploying a particular application or environment. It is launched by running an image. It can package up code and all of its dependencies therefore apps will run quickly and reliably from one computing environment to another.

69. What is the use of Docker_Host?
It will contain container, images, and Docker daemon. It will offer a complete environment to execute and run application.

70. Explain some of the scenario to use Docker? When To Use Docker?
a. Use Docker as version control system for entire app’s operating system.
b. Use Docker when want to distribute/collaborate on app’s operating system with a team.
c. Use Docker to run code on laptop in the same environment as we have on your server (try the building tool).

71. Is Kubernetes and Docker the same?
Kubernetes and Docker isn’t an alternative of each other. Quite the contrary. Kubernetes will run without Docker and Docker will function without Kubernetes. Kubernetes will benefit greatly from Docker and vice versa. Docker is a standalone software which will be installed on any computer to run containerized applications.

72. Explain the difference between Docker and Openshift?
The main difference between Docker and Openshift is that Docker as a project will focuse on the runtime container only, whereas OpenShift as a system will include both the runtime container along the REST API, coordination, and web interfaces for deploying and manage individual containers. A cartridge has similarity to a docker image.

73. Is Docker a virtualization methodology ?
Docker isn’t a virtualization methodology. It relies on other tools that actually implement container-based virtualization or operating system level virtualization.

74. Whether Docker come up with the container technology?
No, Docker did not come up with the container technology. Multiple other development tools offer containers similar to Docker.

75. What are the three main types of Docker components?
The Client, the Host, and the Registry.
The client is the component which will issue “run” and “build” commands to the host.
The host is where all of the containers and images will be created.
They will be then sent to the registry, for execution.

76. Explain how does Docker manage “Dockerized nodes” ?
A Dockerized node can be any machine which has Docker installed and running. Docker will manage both in-house and cloud-based nodes. Therefore, whether the node will exist in the area of the main computer running Docker or it is present on the cloud – it will not matter. Docker can manage it without a problem.

77. How to stop and restart the Docker container?
The following command will be used to stop a certain Docker container with the container id as
CONTAINER_ID:
docker stop CONTAINER_ID
The following command will be used to restart a certain Docker container with the container id as
CONTAINER_ID:
docker restart CONTAINER_ID

78. Difference between Docker Image and container?
The runtime instance of docker image is the Docker container. Docker Image will not have a state, and its state will never change as it will just set of files whereas docker container will have its execution state.

79. How can you run multiple copies of a Compose file on the same host?
Docker’s compose will makes use of the Project name for creating unique identifiers for all of the project’s containers and resources. In order to run multiple copies of the same project, we will required to set a custom project name using the –p command line option or we could use the COMPOSE_PROJECT_NAME environment variable for this purpose.

80. Is there a way to identify the status of a Docker container?
We will identify the status of a Docker container by running the command ‘docker ps –a’, that will in turn list down all the available docker containers with its corresponding statuses on the host. From there we will easily identify the container of interest to check its status correspondingly.

81. What is Hypervisor?
The hypervisor will allow to create a virtual environment in that the guest virtual machines can operate. It will control the guest systems and checks if the resources are allocated to the guests as per requirement.

82. Explain the process of scaling your Docker containers.
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 required the memory and the OS at all times, and there should not be a constraint when the Docker is getting scaled.

83. What is a Dockerfile?
A Dockerfile is a set of instructions. Developers provided Docker with such instructions therefore the program could do the job correctly, with those specific parameters in mind. DockerFile is a text document which is used to assemble a Docker image. It is consist of a list of Docker commands and operating system commands for building an image. These commands will execute automatically in sequence in the Docker environment and create a new Docker image.

 

 

 

 

 

 

 

 

 

 

Author: user

Leave a Reply