Docker Interview Questions and Answers
Question - 91 : - Is it a good practice to run stateful applications on Docker?
Answer - 91 : -
The concept behind stateful applications is that they store their data onto the local file system. You need to decide to move the application to another machine, retrieving data becomes painful. I honestly would not prefer running stateful applications on Docker.
Question - 92 : - How will you monitor Docker in production?
Answer - 92 : -
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.
Question - 93 : - Is it a good practice to run Docker compose in production?
Answer - 93 : -
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.
Question - 94 : - What changes are expected in your docker compose file while moving it to production?
Answer - 94 : -
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
Question - 95 : - Have you used Kubernetes? If you have, which one would you prefer amongst Docker and Kubernetes?
Answer - 95 : -
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.
Question - 96 : - What is the difference between a registry and a repository?
Answer - 96 : - The Docker Registry is a service for hosting and distributing images, whereas the Docker Hub is the default registry. On the other hand, the Docker Repository is the collection of Docker images that are related. That is, they have the same name but different tags.
Question - 97 : - Can JSON be used instead of YAML for the compose file in Docker? If yes, how?
Answer - 97 : -
Yes, JSON can be used instead of YAML for the Docker compose file. To use the JSON file with composing, the filename should be specified as the following:
“docker-compose -f docker-compose.json up.”
Question - 98 : - Explain CMD and ENTRYPOINT in a Dockerfile?
Answer - 98 : -
In a Dockerfile, both CMD and ENTRYPOINT instructions define which command will be executed while running a container. For their cooperation, there are some rules, such as:
- The Dockerfile should specify at least one command from CMD or ENTRYPOINT
- While using the container as an executable, ENTRYPOINT needs to be defined
- When running the container with an alternative argument, CMD will be overridden
Question - 99 : - Explain the process to run an application inside a Linux Container using Docker
Answer - 99 : -
Below are the steps on how to run an application inside the Linux Container using Docker
- Install and run Docker
- Fetch Fedora 21 (Linux based OS) base image from the Docker hub
- Load your application in the Docker base image
- Run container using your new image in interactive mode
- Check the containers in the system
- Start or stop Docker container
- Go inside a Docker container
- Remove container or image
Question - 100 : - What is a Hypervisor?
Answer - 100 : -
A Virtual machine monitor, known as Hypervisor, is software to create and run virtual machines. It allows a single host computer to support more than one guest VMs. This is done by sharing resources like memory, processing, etc., thus reducing the memory, space, and maintenance requirements. There are two types of hypervisor:
- Type I: it is like a lightweight operating system that runs on the host's hardware.
- Type II: runs like software programs on an operating system.