Share with friends

It contains commonly asked Docker questions that can be asked in a freshers role for DevOps or Docker Engineer or an intern.

More on the topic

Docker Books

Docker Interview Questions - Beginner Level

Docker Interview Questions - Medium Level Part 1

Docker Interview Questions - Medium Level Part 2

Docker Interview Questions - Advanced Level Part 1

Docker Interview Questions - Advanced Level Part 2

Docker Interview Questions - Advanced Level Part 3

Docker Interview Questions - Advanced Level Part 4

Beginner Level Docker Interview Questions and Answers

1. What is Docker?

Answer: Docker is a platform that allows you to automate the deployment, scaling, and management of applications. It packages applications and their dependencies into containers, which are lightweight, portable, and run consistently on any environment.

2. What is a Docker container?

Answer: A Docker container is like a tiny, self-contained package. It's got everything it needs to run a piece of software - the code, the runtime, the tools, the libraries, and even the settings. It's like a little world of its own, all wrapped up in one neat little package.

3. What is a Docker image?

Answer: A Docker image is a read-only template that contains the application and its dependencies. Containers are created from images.

4. How is a Docker container different from a virtual machine (VM)?

Answer: Unlike VMs, Docker containers share the host system's kernel and do not require a full OS, making them more lightweight and faster to start. VMs, on the other hand, run a full OS and are more resource-intensive.

5. What is Docker Hub?

Answer: Docker Hub is a cloud-based repository where you can find and share Docker images. It's like GitHub but for Docker images.

6. How do you create a Docker container?

Answer: You create a Docker container using the docker run command. For example:

docker run -d -p 80:80 --name my_container nginx

This command starts up an Nginx container. It runs in the background (detached mode, denoted by -d ) and connects port 80 on your computer to port 80 inside the container.

7. How do you stop a running Docker container?

Answer: Use the docker stop command followed by the container ID or name. For example:

docker stop my_container

8. What is Docker Compose?

Answer: Docker Compose is like a wizard that helps you manage multiple Docker containers at once. It's got this cool YAML file where you can tell it all about your containers, like what they should do and how they should interact with each other.

9. What is a Dockerfile?

Answer: A Dockerfile is a text document that contains all the commands to build a Docker image. It's like a recipe for creating a container image.

10. How do you build a Docker image from a Dockerfile?

Answer: Use the docker build command. For example:

docker build -t my_image .

This builds an image named my_image from the Dockerfile in the current directory (.).

11. What is a Docker volume?

Answer: A Docker volume is a way to persist data generated by and used by Docker containers. Volumes are stored outside the container filesystem, making them independent of the container lifecycle.

12. How do you list all Docker containers?

Answer: Use the docker ps command to list running containers. To list all containers, including stopped ones, use:

docker ps -a

13. What is the difference between docker run and docker start?

Answer: docker run creates and starts a new container, while docker start starts an existing, stopped container.

14. How do you remove a Docker container?

Answer: Type the docker rm command and then the container ID or name. For example:

docker rm my_container

15. How do you remove a Docker image?

Answer: Type the docker rmi command and then the image ID or name. For example:

docker rmi my_image

16. What is the purpose of the docker pull command?

Answer: With the docker pull command, you can grab a Docker image from a registry like Docker Hub.. For example:

docker pull nginx

17. What does the -d flag do in docker run?

Answer: When you use the -d flag, the container will operate in detached mode, allowing it to run in the background while you do other things..

18. How do you access the terminal of a running Docker container?

Answer: Use the docker exec command. For example:

docker exec -it my_container /bin/bash

This opens an interactive terminal (-it) inside the container.

19. What is a Docker network?

Answer: A Docker network allows containers to communicate with each other. By default, Docker creates a bridge network named bridge.

20. How do you create a Docker network?

Answer: Use the docker network create command. For example:

docker network create my_network

21. How do you connect a container to a Docker network?

Answer: Use the --network flag with docker run. For example:

docker run -d --network my_network --name my_container nginx

22. What is the docker logs command used for?

Answer: The docker logs command retrieves logs from a running or stopped container. For example:

docker logs my_container

23. How do you check the status of a Docker container?

Answer: Use the docker ps command to check if the container is running. For more detailed information, use:

docker inspect my_container

24. What is a bind mount in Docker?

Answer: A bind mount is a type of volume that links a directory on the host to a directory in the container. It's useful for sharing files between the host and the container.

25. How do you restart a Docker container?

Answer: Use the docker restart command followed by the container ID or name. For example:

docker restart my_container

26. What is the difference between COPY and ADD in a Dockerfile?

Answer: Both COPY and ADD copy files from the host to the container. COPY is simpler and only copies files, while ADD can also extract tar files and download files from URLs.

27. How do you update a Docker container?

Answer: To update a container, you typically build a new image with the updates and then recreate the container using the new image.

28. What is a Docker registry?

Answer: A Docker registry is like a warehouse for Docker images, where they can be stored and shared. Docker Hub is a well-known public warehouse, but you can also create your own private warehouse.

29. What does the docker inspect command do?

Answer: The docker inspect command returns detailed information about Docker objects, such as containers and images, in JSON format. For example:

docker inspect my_container

30. How do you run a command in an already running Docker container?

Answer: Use the docker exec command. For example, to run a command in a running container:

docker exec my_container ls /app

31. What is the difference between ENTRYPOINT and CMD in a Dockerfile?

Answer: ENTRYPOINT defines the main command to run when the container starts and cannot be overridden at runtime. CMD provides default arguments for the ENTRYPOINT command but can be overridden at runtime.

32. How do you share data between Docker containers?

Answer: You can share data between containers using Docker volumes or by using a Docker network.

33. What does the docker ps -q command do?

Answer: The -q flag with docker ps lists only the container IDs of running containers.

34. What is the default network type for Docker containers?

Answer: By default, the network type is set to "bridge." This means that containers on the same computer can talk to each other.

35. How do you check Docker's version?

Answer: Use the docker --version command to check the installed Docker version.

36. What is the docker-compose.yml file?

Answer: In the docker-compose.yml file, written in YAML, you can describe the components, connections, and storage areas for your Docker Compose application.

37. How do you stop all running Docker containers?

Answer: Use the docker stop command with a list of container IDs or names. To stop all containers, you can use:

docker stop $(docker ps -q)

38. How do you remove all Docker containers?

Answer: Use the docker rm command with a list of container IDs or names. To remove all containers, you can use:

docker rm $(docker ps -aq)

39. How do you remove all Docker images?

Answer: Use the docker rmi command with a list of image IDs or names. To remove all images, you can use:

docker rmi $(docker images -q)

40. What does the docker system prune command do?

Answer: With the docker system prune command, you can get rid of all the stuff that's just taking up space, like stopped containers, networks you're not using anymore, dangling images, and build cache. It's like a spring cleaning for your Docker system!

41. How do you tag a Docker image?

Answer: Use the docker tag command to tag an image with a new name. For example:

docker tag my_image:latest my_image:v1.0

42. What is the purpose of the docker login command?

Answer: With docker login you can use the command to sign into a Docker registry, like Docker Hub, so you can upload and download images.

43. How do you push a Docker image to a registry?

Answer: Use the docker push command followed by the image name. For example:

docker push my_image:v1.0

44. How do you list all Docker images on your system?

Answer: Use the docker images command to list all Docker images.

45. What is the docker save command used for?

Answer: The docker save command saves one or more Docker images to a tar archive. For example:

docker save -o my_image.tar my_image:v1.0

46. What is the docker load command used for?

Answer: The docker load command loads an image from a tar file. For example:

docker load -i my_image.tar

47. How do you rename a Docker container?

Answer: Use the docker rename command followed by the old and new names. For example:

docker rename old_name new_name

48. What does the -p flag do in docker run?

Answer: The -p flag publishes a container's port(s) to the host. For example:

docker run -d -p 8080:80 nginx

This maps port 8080 on the host to port 80 in the container.

49. What is the purpose of the docker cp command?

Answer: The docker cp command copies files or directories between the container and the host. For example:

docker cp my_container:/path/to/file /host/path

50. What does docker run --rm do?

Answer: The --rm flag automatically removes the container when it exits. For example:

docker run --rm my_image

51. How do you set environment variables in a Docker container?

Answer: Use the -e flag in docker run. For example:

docker run -e MY_VAR=value my_image

52. What is Docker Swarm?

Answer: Docker Swarm is like a boss when it comes to managing a group of Docker nodes. It lets you treat them all as one big, happy family, making it easy to keep track of everything.

53. How do you scale a Docker service using Docker Compose?

Answer: Use the docker-compose up --scale command. For example:

docker-compose up --scale web=3

This scales the web service to 3 instances.

54. What is the purpose of the .dockerignore file?

Answer: The .dockerignore file specifies files and directories to ignore when building a Docker image, similar to .gitignore for Git.

55. How do you view the resource usage of Docker containers?

Answer: Use the docker stats command to view real-time resource usage of running containers.

56. What is a multi-stage build in Docker?

Answer: A multi-stage build is a Dockerfile feature that allows you to use multiple FROM statements to create more efficient and smaller images by copying only the necessary artifacts from one stage to another.

57. How do you define dependencies between services in Docker Compose?

Answer: Use the depends_on key in the docker-compose.yml file to define dependencies. For example:

services:
  web:
    depends_on:
      - db
  db:
    image: postgres

58. What does the docker attach command do?

Answer: The docker attach command attaches your terminal to a running container, allowing you to interact with it as if you were inside it.

59. How do you export a Docker container's filesystem as a tar archive?

Answer: Use the docker export command. For example:

docker export -o my_container.tar my_container

60. What is the difference between docker export and docker save?

Answer: docker export exports a container's filesystem as a tar archive, while docker save saves one or more images to a tar archive, including their layers and metadata.

61. How do you start a Docker container with a specific restart policy?

Answer: Use the --restart flag with docker run. For example:

docker run --restart always my_image

This sets the container to always restart on failure.

62. What is a dangling image in Docker?

Answer: A dangling image is an image that is not tagged and not referenced by any container. These images usually result from interrupted builds and can be cleaned up with docker image prune.

63. How do you limit a Docker container's CPU usage?

Answer: Use the --cpus flag in docker run. For example:

docker run --cpus="1.5" my_image

64. How do you limit a Docker container's memory usage?

Answer: Use the -m flag in docker run. For example:

docker run -m 512m my_image

65. What does the docker history command do?

Answer: The docker history command shows the history of an image, including the commands used to build it.

66. How do you pass a file as input to a Docker container?

Answer: You can use volumes to mount the file into the container. For example:

docker run -v /host/path/to/file:/container/path my_image

67. What is the docker update command used for?

Answer: The docker update command is used to dynamically update the configuration of one or more running containers, such as their CPU and memory limits.

68. How do you set a container to auto-remove when stopped?

Answer: Use the --rm flag in docker run. For example:

docker run --rm my_image

69. What does docker-compose down do?

Answer: When you run the "docker-compose down" command, it basically shuts down and gets rid of all the containers, networks, and volumes that are listed in your "docker-compose.yml" file.

70. How do you start all services defined in a Docker Compose file?

Answer: Use the docker-compose up command. For example:

docker-compose up

71. How do you stop all services defined in a Docker Compose file?

Answer: Use the docker-compose down command to stop and remove all services.

72. How do you view logs from a Docker Compose service?

Answer: Use the docker-compose logs command. For example:

docker-compose logs my_service

73. What does the --build flag do in docker-compose up?

Answer: The --build flag forces a rebuild of the Docker images before starting the services. For example:

docker-compose up --build

74. How do you run a one-off command in a Docker Compose service?

Answer: Use the docker-compose run command. For example:

docker-compose run my_service echo "Hello, World!"

75. What is a service in Docker Compose?

Answer: A service in Docker Compose is a container defined in the docker-compose.yml file. It represents a single application or component.

76. How do you check the Docker daemon logs?

Answer: The location of Docker daemon logs depends on your operating system. On Linux, you can usually find them at /var/log/docker.log. Use journalctl for systemd-based systems:

journalctl -u docker.service

77. What does the --link flag do in docker run?

Answer: The --link flag connects two containers by allowing one container to access the other via a specified alias. This feature is now deprecated in favor of Docker networks.

78. What is the default storage driver for Docker on Linux?

Answer: The default storage driver on many Linux distributions is overlay2.

79. How do you start Docker in swarm mode?

Answer: Use the docker swarm init command to initialize a new swarm.

80. What is a Docker service stack?

Answer: A Docker service stack is a collection of services that make up an application in a Docker Swarm. It is defined in a Compose file and deployed with docker stack deploy.

81. How do you list all nodes in a Docker Swarm?

Answer: Use the docker node ls command to list all nodes in the swarm.

82. What is the purpose of the docker secret command?

Answer: The docker secret command is used to manage sensitive data such as passwords and API keys, securely within a Docker Swarm.

83. How do you add a node to a Docker Swarm?

Answer: Use the docker swarm join command on the node you want to add, with the token provided by the swarm manager.

84. How do you remove a node from a Docker Swarm?

Answer: Use the docker node rm command to remove a node from the swarm.

85. What does docker-compose up -d do?

Answer: The -d flag runs the services in detached mode, meaning they run in the background.

86. How do you view the Docker daemon's configuration?

Answer: The Docker daemon's configuration is typically in a file named daemon.json, located in /etc/docker/ on Linux.

87. How do you specify the Dockerfile location when building an image?

Answer: Use the -f flag in docker build. For example:

docker build -t my_image -f /path/to/Dockerfile .

88. What is Docker BuildKit?

Answer: Docker BuildKit is a modern build subsystem for Docker, which offers performance improvements and new features like build secrets and cache management.

89. How do you enable Docker BuildKit?

Answer: Set the environment variable DOCKER_BUILDKIT=1 before running docker build.

90. What is the purpose of the docker service command?

Answer: The docker service command is used to manage services in Docker Swarm, including creating, updating, and scaling services.

91. How do you roll back a service in Docker Swarm?

Answer: Use the docker service rollback command to revert a service to its previous version.

92. What is the purpose of the docker node update command?

Answer: The docker node update command updates the attributes of a node, such as its availability and role within the swarm.

93. What does the docker-compose down --volumes command do?

Answer: The --volumes flag removes all volumes associated with the Docker Compose services when they are stopped.

94. How do you view the history of changes to a Docker image?

Answer: Use the docker history command followed by the image name. For example:

docker history my_image

95. What is the purpose of the docker checkpoint command?

Answer: The docker checkpoint command allows you to checkpoint a running container, saving its state so it can be restored later.

96. How do you restore a container from a checkpoint?

Answer: Use the docker start --checkpoint command to restore a container from a checkpoint. For example:

docker start --checkpoint my_checkpoint my_container

97. What is the purpose of the docker plugin command?

Answer: The docker plugin command manages plugins for Docker, which extend its functionality.

98. How do you list all Docker plugins?

Answer: Use the docker plugin ls command to list all installed plugins.

99. What is Docker Trusted Registry (DTR)?

Answer: Docker Trusted Registry is an enterprise-grade, private Docker image storage solution that allows you to securely store and manage Docker images.

100. How do you secure communication between Docker containers?

Answer: Secure communication can be achieved using encrypted Docker networks, such as overlay networks with encryption enabled.

Next Steps

Docker Books

Docker Interview Questions - Beginner Level

Docker Interview Questions - Medium Level Part 1

Docker Interview Questions - Medium Level Part 2

Docker Interview Questions - Advanced Level Part 1

Docker Interview Questions - Advanced Level Part 2

Docker Interview Questions - Advanced Level Part 3

Docker Interview Questions - Advanced Level Part 4

Share with friends

Priyansh Khodiyar's profile

Written by Priyansh Khodiyar

Priyansh is the founder of UnYAML and a software engineer with a passion for writing. He has good experience with writing and working around DevOps tools and technologies, APMs, Kubernetes APIs, etc and loves to share his knowledge with others.

Life is better with cookies 🍪

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt out if you wish. Cookie Policy