preloader
Docker Interview Questions

50+ Docker Interview Questions and Answers, Prepare Now

author image

To prepare Docker Interview Questions you can check this page. Here we have provided you best Docker interview questions and answers. Practice these Docker interview questions which help you in cracking the interview and getting a job in your dream company. Here we have mostly covered all the Interview questions related to Docker which will help you in acing the interview.

Docker Interview Questions

1. Explain the docker container?

2. Explain docker images?

3. What is a DockerFile?

4. Describe Docker Compose?

5. Tell the docker command that gets the status of all docker containers?

6. How will you lose data stored in a container?

7. Explain the docker image registry?

8. Explain different components of Docker?

9. Explain Docker Hub?

10. Tell the command that you run to export a docker image as an archive?

11. To import a pre-exported Docker image into another Docker host which command will you run?

12. Is it possible to remove the paused container from Docker?

13. To check for the version of the docker client and server which command is used?

14. Tell us the difference between COPY and ADD commands used in a Dockerfile?

15. Can a container restart by itself?

16. Differentiate between a docker Image and Layer?

17. Where are docker volumes stored in docker?

18. What docker info command do?

19. On what systems did Dockers run or perform?

20. How will you log in to the Docker registry?

21. How to make communication between the docker host and Linux host?

22. How to delete a container?

23. Can we use JSON instead of YAML while developing the docker-compose file in Docker?

24. How many containers you can run in docker?

25. Describe the lifecycle stages of Docker Container?

26. Show coding that runs container 1 before container 2 while using docker-compose?

27. Explain Docker Swarm?

28. What is a Docker Namespace?

29. What is the lifecycle of a Docker Container?

30. If you vaguely remember the command and you’d like to confirm it, how will you get help on that particular command?

31. How do you create a docker container from an image?

32. Tell the command to list all the running containers?

33. Suppose you have 3 containers running and out of these, you wish to access one of them. How do you access a running container?

34. Tell us the command to start, stop and kill a container?

35. Can you edit or update a container?

36. How do you push an already worked image to the docker hub?

37. How to delete a stopped container?

38. How to delete an image from local storage?

39. How to build a Dockerfile?

40. Why docker system prune do and its usage?

41. Will you lose your data when a docker container exists?

42. Is there a way to identify the status of a Docker container?

43. Is it better to directly remove the container using the rm command or stop the container followed by removing the container?

44. Is running stateful applications on Docker a good practice?

45. Assume that you have an application with many dependent services. Will docker-compose wait for the current container to be ready to move to the running of the next service?

46. How to monitor Docker in production?

47. Is running a Docker compose in production a good practice?

48. What changes can occur in your docker-compose file while moving it to production?

49. How does load balancing across containers and hosts work?


Learn More Interview Questions Here:


Docker Interview Questions and Answers

1. Explain the docker container?

Docker container contains applications and their dependents. They run as an isolated system and share kernel and system resources with other containers in the host operating system. The main purpose of these docker containers is to remove the infrastructure dependency while organizing and running applications. It means that any containerized application can smoothly work on any platform regardless of the infrastructure being used.

2. Explain docker images?

They are executable packages for creating containers. Here executable packages mean they are bundled up with application code & dependencies, software packages, etc.). These Docker images can be made to any docker environment and the containers can be turned up there to run the application.

3. What is a DockerFile?

A text file that has all the commands which are required to run for building a given image.

4. Describe Docker Compose?

Docker Compose is a YAML file that has all the details of various services, networks, and volumes that are required for making the Docker-based application. So, they create multiple containers, host them and make proper communication between them. For making communication between the containers, ports are exposed by all containers.

5. Tell the docker command that gets the status of all docker containers?

To list the status of all the containers, use the given command: docker ps -a

6. How will you lose data stored in a container?

The data stored in a container is safe and be there until and unless you delete the container data yourself.

7. Explain the docker image registry?

It is a place or an area where you keep safe or store the docker images. Rather than converting the applications to containers every time, a designer can use the images directly from that place where it is stored in the registry. This can either be public or private and Docker hub is the famous public registry available.

8. Explain different components of Docker?

The main three components of docker are:

  • Docker Client: This component carries out “build” and “run” operations to initiate communication with the docker host.
  • Docker Host: This component has a docker daemon which has containers and their associated images to host them. Further, the daemon makes a connection with the docker registry.
  • Docker Registry: Here the docker saves and stores all the docker images. Some of the popular public registries are Docker Hub and Docker Cloud.

9. Explain Docker Hub?

It is an open cloud-based docker registry provided by Docker for saving public images of the containers and allowing them to find and share them with others. To push the image to Docker Hub you can use the docker push command.

10. Tell the command that you run to export a docker image as an archive?

Using the docker save command you run can export a docker image as an archive and the syntax is: docker save -o <exported_name>.tar

11. To import a pre-exported Docker image into another Docker host which command will you run?

Use the docker load command and the syntax is docker load -i <export_image_name>.tar

12. Is it possible to remove the paused container from Docker?

No, it is not possible because a container needs to be in the stopped state to remove it.

13. To check for the version of the docker client and server which command is used?

  • To get all version details of the client and server use the command docker version.
  • To know only server version run command docker version –format ‘{{.Server.Version}}’

14. Tell us the difference between COPY and ADD commands used in a Dockerfile?

Both COPY and ADD commands have the same functionality, but COPY is more used than ADD because of its higher transparency level. COPY helps you in copying local files into the container and ADD gives you additional features to use like remote URL and tar extraction support.

15. Can a container restart by itself?

Yes, it is possible only at the time where you are using certain docker-defined policies and use the docker run command.

1. Off: If the container is stopped or it fails it won’t be restarted

2. On-failure: The container restarts when it feels failures not related to the user.

3. Unless-stopped: This policy makes sure that a container can restart when the proper command is executed to stop it by the user.

4. Always: In this policy, the container always gets restarted Irrespective of the failure or stopping.

These command to be used:

docker run -dit — restart [restart-policy-value] [container_name]

16. Differentiate between a docker Image and Layer?

Image: This is made up of a read-only layer of instructions. An image responds to the docker container which helps in speeding the operation due to the caching mechanism of each step.

Layer: The layer is also an image which runs on instructions.

Example.

FROM ubuntu:18.04 COPY . /myapp RUN make /myapp CMD python /myapp/app.py

17. Where are docker volumes stored in docker?

Volumes are made and organized by Docker and can’t be accessed by non-docker entities. They are saved in the Docker host filesystem at /var/lib/docker/volumes/

18. What docker info command do?

The command provides all the information related to the Docker installed on the host system. These details can be anything like the no. of containers or images or their running state and hardware specifications like total memory, speed, etc.

19. On what systems did Dockers run or perform?

Docker can work on Windows and Linux platforms.

  • For Windows platform: docker requires Windows 10 64bit with 2GB RAM space. You can download docker from https://docs.docker.com/docker-for-windows/ website.
  • For Linux platforms: Linux flavors like Ubuntu >=12.04, Fedora >=19, RHEL >=6.5, CentOS >=6 etc can easily run docker.

20. How will you log in to the Docker registry?

Use the docker login command credentials to log in.

21. How to make communication between the docker host and Linux host?

Use networking by identifying the “ipconfig” on the docker host. This command makes sure that an ethernet adapter is made while the docker is present in the host.

22. How to delete a container?

Follow these two steps for deleting a container:

- docker stop <container_id>

- docker rm <container_id>

23. Can we use JSON instead of YAML while developing the docker-compose file in Docker?

Yes! To run docker-compose with JSON, command docker-compose -f docker-compose.json up can be used.

24. How many containers you can run in docker?

There is no particularly specified limit to the number of containers but it has some limits like hardware restrictions. The size and the CPU resources consumed and available are 2 major factors influencing this limit. If you have good availability of CPU resources, then a large number of containers can run.

25. Describe the lifecycle stages of Docker Container?

The creations of the docker container to its end are known as the docker container life cycle.

The stages are:

  • Creation: When the container is only created but not yet started.
  • Running: The container runs with all its associated processes.
  • Paused: When the running container is paused.
  • Stopped: When the running container is stopped.
  • Deleted: At last when the container is in a dead state.

26. Show coding that runs container 1 before container 2 while using docker-compose?

version: “2.4”
services:
backend:
build: .
depends_on:
- db
db:
image: postgres

27. Explain Docker Swarm?

It is native clustering for Docker. It brings all the hosts together and creates a pool of Docker hosts into a single, virtual Docker host. It serves the standard Docker API, and any tool that is having communicates with a Docker daemon to transparently scale to multiple hosts.

28. What is a Docker Namespace?

It is a Linux feature and an important concept of containers. It adds a layer of isolation in containers. Docker already provides different namespaces to become portable and still not affect the underlying host system. Few namespace types supported by Docker – PID, Mount, IPC, User, Network

29. What is the lifecycle of a Docker Container?

  • 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

30. If you vaguely remember the command and you’d like to confirm it, how will you get help on that particular command?

The following syntax tells provides you with help on how to use a command.

It gives the lists of all the Docker commands.

$ docker –help

If you need help with one particular command, use the given syntax:

$ docker –help

31. How do you create a docker container from an image?

Fetch an image from the docker repository with the given command and run it to create a container. Use the following command:

$ docker run -it -d <image_name>

32. Tell the command to list all the running containers?

Use the command to list down all the running containers:

$ docker ps

33. Suppose you have 3 containers running and out of these, you wish to access one of them. How do you access a running container?

To access a running container:

$ docker exec -it bash

The command allows you to get inside a container and work with it.

34. Tell us the command to start, stop and kill a container?

To start a docker container use command:

$ docker start <container_id>

To stop a running docker container use command:

$ docker stop <container_id>

To kill a docker container use command:

$ docker kill <container_id>

35. Can you edit or update a container?

Yes, you can edit or update a container by using just one command.

$ docker commit <username/imagename>

36. How do you push an already worked image to the docker hub?

$ docker push <username/image name>

37. How to delete a stopped container?

By using this command you can delete a stopped container:

$ docker rm

38. How to delete an image from local storage?

By using this command you can delete an image from the local system:

$ docker rmi

39. How to build a Dockerfile?

Once you’ve texted or written a Dockerfile, you need to form it to make an image with those specifications by using the command:

$ docker build

40. Why docker system prune do and its usage?

$ docker system prune

By using the stated command you can remove all the stopped containers, \ networks that all dangling images and all build caches that are not in use.

41. Will you lose your data when a docker container exists?

No, there is no loss of any data when the Docker container exits. Any data that is written to the container gets saved on the disk until you delete the container. The file system continues working for the container even after it halts.

42. Is there a way to identify the status of a Docker container?

Use the given command to check docker state at any given point:

$ docker ps

If by default the above command lists down the only running containers. Use the command to list all containers

$ docker ps -a

43. Is it better to directly remove the container using the rm command or stop the container followed by removing the container?

It’s always preferred to stop the container and then remove it using the remove command.

$ docker stop <coontainer_id>

$ docker rm -f <container_id>

Firstly stopping the container and then removing it sends SIG_HUP signal to recipients. This makes sure that all the containers have time to clean up their tasks. This is done to avoid unwanted errors.

44. Is running stateful applications on Docker a good practice?

The stateful application stores its data in the local file system. If you need to move the application to another device, then retrieving data is painful. So that is why it is not preferred to run stateful applications on Docker.

45. Assume that you have an application with many dependent services. Will docker-compose wait for the current container to be ready to move to the running of the next service?

Yes, docker-compose always runs as per the dependency order. These dependencies are specified on the commands like depends_on, links, volumes_from, etc.

46. How to monitor Docker in production?

Docker gives different functionalities like docker stats and docker events to monitor docker in production. Docker stats allows and gives CPU and memory usage of the container. Docker event gives details about the activities taking place in the docker daemon.

47. Is running a Docker compose in production a good practice?

Yes, when you explain applications with docker-compose, you can use this compose definition at other production stages like CI, staging, testing, etc.

48. What changes can occur in your docker-compose file while moving it to production?

These are some changes you are required to make to compose file before moving your application to the production environment:

  • Remove volume bindings, that helps the code stays in the container and can’t be altered from outside.
  • Binding to different ports on the host.
  • Specify a restart policy
  • Add extra services like log aggregator

49. How does load balancing across containers and hosts work?

If you use the docker service with multiple containers across different hosts, you need to load balance the incoming traffic. Load balancing and HAProxy are required to balance the incoming traffic across different containers. If any of the containers crash, another container should start running and the traffic should be diverted to this new running container.

This is the Docker Interview Questions which helps you to crack the interview and helps you to ease your competition with good practice. If you want to read these same types of pages Docker Interview question and answer you can visit this website.


Want to prepare for these languages:

Recent Articles