In this article, We are going to cover Real time Docker Interview questions and answers for Fresher and Experienced candidate.
We have friends who are working in DevOps,We have contacted them and collected below Practical docker interview questions and their answers which can be asked in interview.
Docker Interview Questions and Answers
1. What according to you is Docker?
A Docker can be a platform designed to ensure excellent efficiency and availability by containerizing the application and segregating them from each other for environments like production, testing or development.
2. Define Docker hub or Docker Hub Registry?
Docker hub is a cloud-based registry service that lets you attach, create and send your assets to application databases, save images that have been manually sent, and connects to Docker cloud so that you can you can deploy images to your hosts.
Docker hub provides a centralized resource for container image discovery, distribution and change management, user and team collaboration, workflow automation throughout the development pipeline.
3. What is command to pull docker image
$ docker pull [OPTIONS] [PATH/]IMAGE_NAME[:TAG]
$ docker pull ubuntu
4. How to pull docker image with specific version
$ docker pull ubuntu:18.04
5. How to pull the latest version of an image
$ docker pull ubuntu:latest
6. How to create a custom tag to docker image
$ docker tag ubuntu:latest fosstechnix/ubuntu:test
7. How to push docker image to docker hub registry using command line
$ docker push fosstechnix/ubuntu:demo
8. How to Remove all images in docker server
$ docker image rm -f <Image_id>
9. How to Pull your custom image from your docker account
$ docker pull fosstechnix/ubuntu:demo
10. How to pull Docker Image from Private Registry
First login to Private Registry
$ docker login myrepo.fosstechnix.com:9000
Then pull your images
$ docker pull [OPTIONS] ADDRESS:PORT[/PATH]/IMAGE_NAME[:TAG]
$ docker pull repo.fosstechnix.com:9000/demo-image
11. What do you mean by Docker container?
The program and all its components are included in Docker containers. The kernel is associated with several other containers and works in the host operating system as independent operations.
12. Tell me some about Hypervisor.
Hypervisor can also termed as the virtual machine monitor. This system basically divides the hosting system by delegating resources to each system equally. The possibility of turning virtualization into feasibility and practicality can be achieved only with Hypervisor.
13. Can you state the advantages of Docker over Hypervisor?
The prominent advantage of using Docker over Hypervisor is lightweight feature of the former one makes it highly feasible in terms of operations.
14. Define Docker images.
Docker images are required for establishing Docker containers. These images can be used for linking to any of the Docking environment.
15. How do you estimate the Docker server version and the client?
$ docker version
command will give the requisite information regarding the Docker client and server version.
16. Tell me something about Docker machine.
Docker machines are basically used for clustering of Docker swarms. Moreover, they are used for installation of Docker engines on the virtual hosting facilities, which can be managed using the commands from Docker machines.
17. Define Docker Swarms.
Docker swarms functions mainly by splitting a collection of Docker hosts into individual and virtual hosting spaces. As a result, the maintenance turns very easy and feasible in its operations.
18. Describe the usage of Dockerfile?
A Dockerfile is a series of specific instructions something we must send Docker to create the files. We can see the Dockerfile as a word document that has all the required commands to build a Docker Image.
A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
Below is workflow to create Docker Container from Dockerfile
Dockerfile –> Docker Image –> Docker Container
19. Can you please write Dockerfile to create Ubuntu Docker Image
FROM ubuntu:18.04 MAINTAINER FOSS TECHNix [email protected] LABEL version="1.0" \ RUN apt-get update && apt-get install -y apache2 && apt-get clean ENV APACHE_RUN_USER www-data ENV APACHE_RUN_GROUP www-data ENV APACHE_LOG_DIR /var/log/apache2 EXPOSE 80 COPY index.html /var/www/html CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
20. Can you please write Dockerfile to create Node Js Docker Image
FROM node:10 RUN mkdir -p /home/nodejs/app WORKDIR /home/nodejs/app COPY package.json . RUN npm install COPY . . CMD [“node.js”, “index.js”] EXPOSE 3000
21. What is command to build docker image from Dockerfile ?
$ docker build -t image_name .
22. What is the command to run the image as a container?
$ docker run -it ubuntu /bin/bash
Here i -> interactive, t -> terminal
23. What is command to list docker images
$ docker images
24. What is command to list specific docker image
$ docker image ls <imagename>
25. How to apply port mapping a running container?
We can apply port forwarding while running a container using below command.
$ docker run -p <public_port>:<private_port> -d <image>
26. What is command to login docker container
$ docker exec -it <container_Name> /bin/bash
27. What is command to stop a docker container
$ docker stop <container_id>
28. What is command to start a docker container
$ docker start <container_id>
29. What is command to remove a Docker container
$ docker rm <container_id>
30. What is command to list out Running Docker containers
$ docker ps
31. What are the common instructions in Dockerfile
Below are some common instructions in Dockerfile
FROM, MAINTAINER, RUN, CMD, LABEL, EXPOSE, ENV, ADD, COPY, ENTRYPOINT, VOLUME, USER, WORKDIR, ARG, ONBUILD, STOPSIGNAL, SHELL, HEALTHCHECK
32. What is difference between ADD and COPY in Dockerfile
COPY : Copies a file or directory from your host to Docker image, It is used to simply copying files or directories into the build context.
COPY <source> <destination>
COPY index.html /var/www/html
ADD: Copies a file and directory from your host to Docker image, however can also fetch remote URLs, extract TAR/ZIP files, etc. It is used downloading remote resources, extracting TAR/ZIP files.
ADD <source> <destination>
ADD java/jdk-8u231-linux-x64.tar /opt/jdk/
33. Detail us with some of the specific advantages of Docker over other containerization technologies.
- Different types of files can be downloaded from a central space along with the Docker hub.
- Docker also enables us to share our contents with our created containers.
- It can be assessed from the official IT systems or even from the personal computers also.
34. Enumerate the lifecycle process of Docker containers
- Establishing the containers.
- Using the container.
- Halting the container.
- Destroying the container.
35. What are Docker Namespaces?
Docker Namespaces is a platform that provides a container known as independent workspaces. A variety of namespaces are generated for this database after a container is launched.
Such namespaces include a seclusion framework for the containers since each container operates in a different namespace with limited access to the namespace defined.
36. What is the EXPOSE command? What is its role?
EXPOSE <port> [<port>/<protocol>...]
During publishing of the ports, this command can be used for mapping of the documentations.
37. Why is it necessary to monitor a Docker?
Active monitoring ensures higher productivity and better outcomes. Docker monitoring also notifies about any default in the system.
38. Define Docker compose?
Docker Compose is a method for specifying various containers and their parameters in a YAML or JSON. Docker Compose more usually uses one or several dependencies, for instance MySQL or MongoDB, for your program.
This dependencies are usually set up locally throughout innovation — a process which then has to be reworked before going to a production set-up. You can use Docker Compose to prevent these deployment and configuration bits.
Docker compose is used to Defining and Running multi container Docker Application, you can use JSON or YAML file to write docker compose
39. Can Please create Nodejs, MySQL, MongoDB docker environments using docker-compose file ?
version: "2" services: web: build: . ports: - "3000:3000" depends_on: - mongo - mysql mongo: image: mongo volumes: - my-datavolume:/var/lib/mongo volumes: my-datavolume: ports: - "27017:27017" mysql: env_file: - mysql-server.env image:mysql volumes: - my-datavolume:/var/lib/mysql volumes: my-datavolume: ports: - "3306:3306"
40. What is command to run Docker compose
$ docker-compose up
41. What is depends_on in Docker compose
It is used to Link to containers in another service and also express dependency between services.
42. Can We use JSON instead of YAML for my compose file in Docker
Yes. We can Use.
43. Describe the role of Docker load and save command.
Docker save command makes its possible to export a Docker image as an archive with command:
$ docker save -o <container-export-path>.tar <container-name>
44. While this exported image can be easily imported to other hosts using the load command.
$ docker load -i <container-path>.tar
45. Why and how to identify the status of a Docker container?
Identification of the status helps us to make any conduct to the Docker containers accordingly. Therefore, for identifying the same we need to run the following command.
$ docker ps –a
46. Which is the most feasible type of application for Docker containers – Stateless or Stateful?
It is best to generate a Stateless Docker container application. From our code we could build a container and remove programmable state parameters from framework. Now in development and in QA environments we can operate the same container with different parameters.
This allows to recreate the same image in various scenarios. A stateless framework is also much simpler than a superb program to scale with Docker Containers.
47. Differentiate between a Docker layer and a image.
The layers in a Docker represents the set of instructions from a Docker image, while the image is nothing but the set of read-only layers.
48. Say something about virtualization.
A way of logically separating mainframes is seen as virtualization what allows multiple software to run concurrently. The situation changed radically, though, as businesses and open source networks could provide a way to handle delegated instructions in one manner or another, allowing multiple operating systems to operate on a single x86-based machine concurrently.
49. What if you have accidentally out of the Docker containers, will you loose the files?
There is no way we can loose our progress in a Docker container unless we have implemented the deleting program in the container itself.
50. What are factors that decides the number of containers you can run on?
Factors such as app size and strength of the CPU can deliberately influence the count of Docker containers. Thus, it can be understood that if we are equipped goof CPU strength we can easily hell load of containers with extreme ease.
51. What is the difference between CMD and ENTRYPOINT in a Dockerfile?
CMD in Dockerfile Instruction is used to execute a command in Running container, There should be one CMD in a Dockerfile.
ENTRYPOINT in Dockerfile Instruction is used you to configure a container that you can run as an executable.
52. What is Dockerfile Instructions ?
Dockerfile contains a set of Instructions to build Docker Image -> from Docker Image -> running Docker container
We have covered docker interview questions and answers for fresher and experienced candidate.
53. What are Docker Lifecycle commands ?
Below are some Docker Lifecycle commands for every Docker Container
- Docker create
- docker run
- docker pause
- docker unpause
- docker stop
- docker start
- docker restart
- docker attach
- docker wait
- docker rm
- docker kill
54. What is Docker Prune ?
Using Docker prune we can delete unused or dangling containers, Images , volumes and networks
We have covered docker interview questions and answers for fresher and experienced candidate.