1. What is Docker?
Ans: Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works seamlessly in any environment, be it development, test or production. Docker containers, wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries, etc. It wraps basically anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.
2. What is Docker container?
Ans: This is a very important question so just make sure you don’t deviate from the topic and I will advise you to follow the below mentioned format:
1. Docker containers include the application and all of its dependencies, but share the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers are not tied to any specific infrastructure: they run on any computer, on any infrastructure, and in any cloud.
2. 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.
3. Docker containers are basically runtime instances of Docker images.
3. What is a Docker Registry?
Ans: A Docker Registry is a place where all the Docker Images will be stored and Docker Cloud and Docker Hub are the public registries where these images can be hosted upon. The Docker hub is the default storage for the Docker Images. An own registry can also be set up as per the requirement. Docker Data Center (DDC) can also be used which includes DTR (Docker Trusted Registry). Docker store will provide the feature of buying and selling the Docker images.
4. What is the benefit of using a Docker over a Hypervisor?
Ans: Though Docker and Hypervisor might do the same job overall, there are many differences between them in terms of how they work. Docker can be thought of as lightweight since it uses very fewer resources and also the host kernel rather than creating it like a Hypervisor.
5. Explain basic Docker usage workflow?
Ans: Everything starts with the Dockerfile. The Dockerfile is the source code of the Image.
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.
6. What is a Docker Namespace?
Ans: A namespace is one of the Linux features and an important concept of containers. Namespace adds a layer of isolation in containers. Docker provides various namespaces in order to stay portable and not affect the underlying host system. Few namespace types supported by Docker – PID, Mount, IPC, User, Network.
7. Will cloud overtake the use of Containerization?
Ans: Docker containers are gaining popularity but at the same time, Cloud services are giving a good fight. In my personal opinion, Docker will never be replaced by Cloud. Using cloud services with containerization will definitely hype the game. Organizations need to take their requirements and dependencies into consideration into the picture and decide what’s best for them. Most of the companies have integrated Docker with the cloud. This way they can make the best out of both the technologies.
8. 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.
The interviewer does not just expect definitions, hence explain how to use a Dockerfile which comes with experience. Have a look at this tutorial to understand how Dockerfile works.
9. How is Docker different from other containerization methods?
Ans: Docker containers are very easy to deploy in any cloud platform. It can get more applications running on the same hardware when compared to other technologies, it makes it easy for developers to quickly create, ready-to-run containerized applications and it makes managing and deploying applications much easier. You can even share containers with your applications.
10. How to create Docker container?
Ans: You can create a Docker container out of any specific Docker image of your choice and the same can be achieved using the command given below.
docker run -t -i command name
The command above will create the container and also starts it for you. In order to check whether the Docker container is created and whether it is running or not, you could make use of the following command. This command will list out all the Docker containers along with its statuses on the host that the Docker container runs.
11. What type of applications – Stateless or Stateful are more suitable for Docker Container?
Ans: It is preferable to create Stateless application for Docker Container. We can create a container out of our application and take out the configurable state parameters from application. Now we can run same container in Production as well as QA environments with different parameters. This helps in reusing the same Image in different scenarios. Also a stateless application is much easier to scale with Docker Containers than a stateful application.
12. Is it a good practice to run Docker compose in production?
Ans: Yes, using docker compose in production is the best practical application of docker compose. When you define applications with compose, you can use this compose definition in various production stages like CI, staging, testing, etc.
13. What is Docker Hub?
Ans: Docker images create docker containers. There has to be a registry where these docker images live. This registry is Docker Hub. Users can pick up images from Docker Hub and use them to create customized images and containers. Currently, the Docker Hub is the world’s largest public repository of image containers.
14. What is the use of a Dockerfile?
Ans: A Dockerfile is a set of specific instructions that we need to pass on to Docker so that the images can be built. We can think of the Dockerfile as a text document which has all the commands that are needed for creating a Docker image. We can create an automated build that lets us execute multiple command lines one after the other.
15. What is virtualisation?
Ans: In its conceived form, virtualisation was considered a method of logically dividing mainframes to allow multiple applications to run simultaneously. However, the scenario drastically changed when companies and open source communities were able to provide a method of handling the privileged instructions in one way or another and allow for multiple operating systems to be run simultaneously on a single x86 based system.
16. How far do Docker containers scale? Are there any requirements for the same?
Ans: Large web deployments like Google and Twitter and platform providers such as Heroku and dotCloud, all run on container technology. Containers can be scaled to hundreds of thousands or even millions of them running in parallel. Talking about requirements, containers require the memory and the OS at all the times and a way to use this memory efficiently when scaled.
17. What is a Docker Swarm?
Ans: We can think of a Docker Swarm as the way of orchestrating the Docker containers. We will be able to implement Dockers in a cluster. We can convert our Docker pools into a single Docker Swarm for easy management and monitoring.
18. How many containers can run per host?
Ans: There can be as many containers as you wish per host. Docker does not put any restrictions on it. But you need to consider every container needs storage space, CPU and memory which the hardware needs to support. You also need to consider the application size. Containers are considered to be lightweight but very dependant on the host OS.
19. What is Docker image?
Ans: Docker image can be understood as a template from which Docker containers can be created as many as we want out of that single Docker image. Having said that, to put it in layman terms, Docker containers are created out of Docker images. Docker images are created with the build command, and this produces a container that starts when it is run. Docker images are stored in the Docker registry such as the public Docker registry (registry.hub.docker.com) as these are designed to be constituted with layers of other images, enabling just the minimal amount of data over the network.
20. Is there a possibility that a container can restart all by itself in Docker?
Ans: To answer this question blatantly, No, it is not possible. The default –restart flag is set to never restart on its own. If you want to tweak this, then you may give it a try.
21. What is the lifecycle of Docker Container?
Ans: This is the most popular Docker Interview Questions asked in an interview.
The life cycle of the Docker container is as below:
- Create a container.
- Run the Docker container.
- Pause the Container.
- Unpause the Container.
- Start the Container.
- Stop the Container.
22. 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.
23. Can you remove a paused container from Docker?
Ans: The answer is no. You cannot remove a paused container. The container has to be in the stopped state before it can be removed.
24. Suppose you have an application that has many dependant services. Will docker compose wait for the current container to be ready to move to the running of the next service?
Ans: The answer is yes. Docker compose always runs in the dependency order. These dependencies are specifications like depends_on, links, volumes_from, etc.
25. What are the unique features of Docker over other containerization technologies?
Ans: Some of the most important and unique features of Docker are as follows:
We can run our Docker container either on our PC or on our enterprise IT system.
Along with the Docker Hub, which is a repository of all containers, we can deploy and download all our applications from a central location.
We can even share our applications with the containers that we create.
26. What is Docker Swarm can be best understood as the native way of Clustering implementation for Docker itself?
Ans: Docker Swarm turns a pool of Docker hosts into a single and virtual Docker host. It serves the standard Docker API or any other tool that can already communicate with a Docker daemon can make use of Docker Swarm to scale in a transparent way to multiple hosts. Following are the list of some of the supported tools that will be helpful in achieving what we have discussed just now.
- Docker Compose
- Docker Machine
27. How do I run multiple copies of a Compose file on the same host?
Ans: Docker’s compose makes use of the Project name to create unique identifiers for all of the project’s containers and resources. In order to run multiple copies of the same project, you will need to set a custom project name using the –p command line option or you could use the COMPOSE_PROJECT_NAME environment variable for this purpose.
28. Is there a possibility to include specific code with COPY/ADD or a volume?
Ans: This can be easily achieved by adding either the COPY or the ADD directives in your dockerfile. This will count to be useful if you want to move your code along with any of your Docker images, example, sending your code an environment up the ladder – Development environment to the Staging environment or from the Staging environment to the Production environment.
29. How to build envrionment-agnostic systems with Docker?
Ans: There are three main features helping to achieve that:
- Environment variable
- Read-only file systems
30. What is the difference between Docker Image and Layer?
Ans: Image: A Docker image is built up from a series of read-only layers
Layer: Each layer represents an instruction in the image’s Dockerfile.
The below Dockerfile contains four commands, each of which creates a layer.
31. what does the ‘-d’ flag mean in the command?
Ans: -d means the container needs to start in the detached mode. Explain a little about the detach mode. Have a look at this blog to get a better understanding of different docker commands.
32. Will you lose your data, when a docker container exists?
Ans: No, you won’t lose any data when Docker container exits. Any data that your application writes to the container gets preserved on the disk until you explicitly delete the container. The file system for the container persists even after the container halts.
33. Is it better to directly remove the container using the rm command or stop the container followed by remove container?
Ans: Its always better to stop the container and then remove it using the remove command.
$ docker stop
$ docker rm -f
Stopping the container and then removing it will allow sending SIG_HUP signal to recipients. This will ensure that all the containers have enough time to clean up their tasks. This method is considered a good practice, avoiding unwanted errors.
34. What changes are expected in your docker compose file while moving it to production?
Ans: These are the following changes you need make to your compose file before migrating your application to the production environment.
Remove volume bindings, so the code stays inside the container and cannot be changed from outside the container.
Binding to different ports on the host.
Specify a restart policy
Add extra services like log aggregator.
35. Why is Docker the new craze in virtualization and cloud computing?
Ans: Docker is the newest and the latest craze in the world of Virtualization and also Cloud computing because it is an ultra-lightweight containerization app that is brimming with potential to prove its mettle.
36. Will cloud automation overtake containerization any sooner?
Ans: Docker containers are gaining the popularity each passing day and definitely will be a quintessential part of any professional Continuous Integration / Continuous Development pipelines. Having said that there is equal responsibility on all the key stakeholders at each Organization to take up the challenge of weighing the risks and gains on adopting technologies that are budding up on a daily basis. In my humble opinion, Docker will be extremely effective in Organizations that appreciate the consequences of Containerization.
37. How do you get the number of containers running, paused and stopped?
Ans: You can use the following command to get detailed information about the docker installed on your system.
Instructor-led Sessions Real-life Case Studies Assignments Lifetime Access
You can get the number of containers running, paused, stopped, the number of images and a lot more.
38. Can you use a container, edit it, and update it? Also, how do you make it a new and store it on the local system?
Ans: Of course, you can use a container, edit it and update it. This sounds complicated but its actually just one command.
$ docker commit <username/imagename>.
39. Tell us something about Docker Compose?
Ans: Docker Compose is a YAML file which contains details about the services, networks, and volumes for setting up the Docker application. So, you can use Docker Compose to create separate containers, host them and get them to communicate with each other. Each container will expose a port for communicating with other containers.
40. How to start, stop and kill a container?
Ans: The following command is used to start a docker container:
$ docker start
and the following for stopping a running container:
$ docker stop
kill a container with the following command:
$ docker kill.
41. How will you monitor Docker in production?
Ans: Docker provides functionalities like docker stats and docker events to monitor docker in production. Docker stats provides CPU and memory usage of the container. Docker events provide information about the activities taking place in the docker daemon.
42. Have you used Kubernetes? If you have, which one would you prefer amongst Docker and Kubernetes?
Ans: Be very honest in such questions. If you have used Kubernetes, talk about your experience with Kubernetes and Docker Swarm. Point out the key areas where you thought docker swarm was more efficient and vice versa. Have a look at this blog for understanding differences between Docker and Kubernetes.
You Docker interview questions are not just limited to the workarounds of docker but also other similar tools. Hence be prepared with tools/technologies that give Docker competition. One such example is Kubernetes.
43. 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.
44. What are the differences between the ‘docker run’ and the ‘docker create’?
Ans: The most important difference that can be noted is that, by using the ‘docker create’ command we can create a Docker container in the Stopped state. We can also provide it with an ID that can be stored for later usages as well.
This can be achieved by using the command ‘docker run’ with the option –cidfile FILE_NAME as like this.
‘docker run –cidfile FILE_NAME’
45. How to delete a stopped container?
Ans: Use the following command to delete a stopped container.
$ docker rm.
46. When do you use “.dockerfile_name” and when to use the entire path?
Ans: Use “.dockerfile_name” when the dockerfile exits in the same file directory and you use the entire path if it lives somewhere else.
47. How to delete an image from the local storage system?
Ans: The following command lets you delete an image from the local system:
$ docker rmi.
48. What is the advantage of Docker over hypervisors?
Ans: Docker is light weight and more efficient in terms of resource uses because it uses the host underlying kernel rather than creating its own hypervisor.
49. What, in your opinion, is the most exciting potential use for Docker?
Ans: The most exciting potential use of Docker that I can think of is its build pipeline. Most of the Docker professionals are seen using hyper-scaling with containers, and indeed get a lot of containers on the host that it actually runs on. These are also known to be blatantly fast. Most of the development – test build pipeline is completely automated using the Docker framework.
50. What are the various states that a Docker container can be in at any given point in time?Ans: There are four states that a Docker container can be in, at any given point in time. Those states are as given as follows:
All Docker Interview Questions
Docker VideosDuration: 25+ Hours
- Experienced Faculty
- Real-time Scenarios
- Free Bundle Access
- Course Future Updates
- Sample CV/Resume
- Interview Q&A
- Complimentary Materials