Docker MCQs

Let’s go through 50 Docker MCQs covering a wide range of topics from basic concepts to advanced features of Docker.

1. What is Docker?

a) A cloud-based storage service

b) A containerization platform for deploying applications

c) A virtualization platform for running VMs

d) A configuration management tool

Answer: b) A containerization platform for deploying applications



2. Which of the following is the main benefit of Docker?

a) Better performance compared to VMs

b) Lightweight and fast deployment of applications

c) Easier to debug applications

d) Uses a large amount of memory for application deployment

Answer: b) Lightweight and fast deployment of applications



3. What is a Docker container?

a) A virtual machine with a full OS

b) A portable unit of software containing everything needed to run an application

c) A storage volume

d) A command-line interface for Docker

Answer: b) A portable unit of software containing everything needed to run an application



4. Which of the following is NOT a valid Docker object?

a) Image

b) Container

c) Volume

d) User

Answer: d) User



5. What command is used to build a Docker image?

a) docker start

b) docker build

c) docker run

d) docker create

Answer: b) docker build



6. Which command is used to start a container in Docker?

a) docker start

b) docker run

c) docker create

d) docker launch

Answer: b) docker run



7. What is a Docker image?

a) A running instance of a container

b) A static template used to create containers

c) A Docker registry

d) A configuration file for a container

Answer: b) A static template used to create containers



8. Which of the following is a Docker registry service?

a) Docker Hub

b) GitHub

c) Jenkins

d) Kubernetes

Answer: a) Docker Hub



9. What is the purpose of the Dockerfile?

a) To configure Docker networking

b) To define the steps to build a Docker image

c) To deploy containers

d) To check Docker container health

Answer: b) To define the steps to build a Docker image



10. How do you list all the running containers in Docker?

a) docker ps -a

b) docker containers list

c) docker ps

d) docker list

Answer: c) docker ps



11. What is Docker Compose used for?

a) Running multiple Docker containers as a single service

b) Building Docker images

c) Creating Docker networks

d) Installing Docker on a server

Answer: a) Running multiple Docker containers as a single service



12. What is the default network driver in Docker?

a) Host

b) Bridge

c) Overlay

d) None

Answer: b) Bridge



13. Which command is used to stop a running Docker container?

a) docker stop

b) docker halt

c) docker terminate

d) docker remove

Answer: a) docker stop



14. What is the purpose of Docker volumes?

a) Storing images

b) Storing logs for containers

c) Sharing data between containers and the host

d) Configuring network settings

Answer: c) Sharing data between containers and the host



15. What is the purpose of Docker networking?

a) To allow communication between containers and the outside world

b) To configure the Docker registry

c) To manage container resources

d) To monitor containers

Answer: a) To allow communication between containers and the outside world



16. Which of the following commands is used to remove a stopped Docker container?

a) docker rm

b) docker delete

c) docker remove

d) docker stop

Answer: a) docker rm



17. What is the default port for Docker Hub?

a) 80

b) 443

c) 5000

d) 8000

Answer: c) 5000



18. How can you see the logs of a running container?

a) docker logs <container_id>

b) docker view <container_id>

c) docker show logs

d) docker inspect <container_id>

Answer: a) docker logs <container_id>



19. What is the command to build a Docker image from a Dockerfile?

a) docker create <Dockerfile>

b) docker build -t <image_name> .

c) docker start <image_name>

d) docker image build -t <image_name> .

Answer: b) docker build -t <image_name> .



20. What does the docker pull command do?

a) Pulls an image from a Docker registry to the local machine

b) Starts a container

c) Pushes a local image to Docker Hub

d) Downloads Docker updates

Answer: a) Pulls an image from a Docker registry to the local machine



21. Which Docker command is used to create a new container from an image?

a) docker new

b) docker run

c) docker create

d) docker build

Answer: b) docker run



22. What is Docker Swarm?

a) A load balancing service

b) A container orchestration tool for Docker

c) A logging system

d) A data storage solution

Answer: b) A container orchestration tool for Docker



23. What is the purpose of the docker exec command?

a) To start a new container

b) To execute a command inside a running container

c) To execute a Docker command on the host machine

d) To build a Docker image

Answer: b) To execute a command inside a running container



24. Which file is used to configure Docker Compose services?

a) Dockerfile

b) docker-compose.yml

c) docker-compose.config

d) docker.yaml

Answer: b) docker-compose.yml



25. What is the purpose of the docker inspect command?

a) To display detailed information about a container or image

b) To list all containers

c) To stop a container

d) To remove a container

Answer: a) To display detailed information about a container or image



26. Which of the following Docker commands would show you the running containers with detailed information?

a) docker ps -l

b) docker ps -v

c) docker ps -a

d) docker ps

Answer: d) docker ps



27. What does the docker push command do?

a) Pushes changes to a Docker container

b) Pushes a local Docker image to a registry

c) Pushes Docker updates to the local machine

d) Pushes logs to Docker Hub

Answer: b) Pushes a local Docker image to a registry



28. What is the purpose of the –rm flag when running a Docker container?

a) Automatically remove the container after it stops

b) Restrict the container’s network usage

c) Automatically restart the container if it fails

d) Set a maximum resource limit for the container

Answer: a) Automatically remove the container after it stops



29. What is Docker Hub?

a) A local registry for Docker images

b) A cloud service for running containers

c) A public repository for Docker images

d) A Docker management tool

Answer: c) A public repository for Docker images



30. What is the Docker command to remove an image?

a) docker delete

b) docker image rm

c) docker remove image

d) docker stop image

Answer: b) docker image rm



31. What does the docker network ls command do?

a) Lists all Docker containers

b) Lists all Docker images

c) Lists all Docker networks

d) Lists all Docker volumes

Answer: c) Lists all Docker networks



32. What is the purpose of Docker volumes?

a) To provide persistent storage for containers

b) To store Docker images

c) To enable Docker container communication

d) To increase the speed of Docker builds

Answer: a) To provide persistent storage for containers



33. Which command is used to get information about the Docker daemon?

a) docker info

b) docker status

c) docker version

d) docker daemon info

Answer: a) docker info



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

a) A build process that uses multiple containers

b) A Dockerfile with multiple build steps for smaller, more efficient images

c) A process for orchestrating containers

d) A method of creating multiple versions of an image

Answer: b) A Dockerfile with multiple build steps for smaller, more efficient images



35. What does the docker stats command do?

a) Shows the status of all containers

b) Displays resource usage statistics of running containers

c) Displays the logs of running containers

d) Displays network stats

Answer: b) Displays resource usage statistics of running containers



36. Which of the following is the main Docker configuration file?

a) docker-compose.yml

b) .dockerfile

c) docker.conf

d) Dockerfile

Answer: d) Dockerfile



37. What is the default execution environment for a Docker container?

a) Shell

b) Linux-based

c) Windows-based

d) Java Runtime Environment

Answer: b) Linux-based



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

a) To log in to the Docker Hub registry

b) To log in to a container

c) To log in to the Docker daemon

d) To authenticate with a custom registry

Answer: a) To log in to the Docker Hub registry



39. What is the Docker command to run a container in the background?

a) docker exec

b) docker start

c) docker run -d

d) docker create

Answer: c) docker run -d



40. How do you check the version of Docker installed on your system?

a) docker version

b) docker info

c) docker –version

d) Both a and c

Answer: d) Both a and c



41. What is the purpose of docker-compose.yml?

a) It defines the network settings of containers

b) It defines multiple containers and services for Docker Compose

c) It defines a single container for Docker

d) It defines the Docker daemon settings

Answer: b) It defines multiple containers and services for Docker Compose



42. How do you remove a Docker volume?

a) docker rm volume_name

b) docker volume rm

c) docker remove volume_name

d) docker volume delete

Answer: b) docker volume rm



43. What is Docker’s default port for communication?

a) 22

b) 80

c) 443

d) 2375

Answer: d) 2375



44. Which command allows you to run a command inside a running container?

a) docker run

b) docker exec

c) docker start

d) docker attach

Answer: b) docker exec



45. Which of the following Docker components is responsible for the Docker container’s configuration and resources?

a) Docker Image

b) Docker Container

c) Docker Engine

d) Docker Hub

Answer: b) Docker Container



46. Which of the following commands is used to list all images in Docker?

a) docker list images

b) docker image list

c) docker images

d) docker ps -a

Answer: c) docker images



47. What is Docker Desktop?

a) A GUI tool for managing Docker containers and images

b) A CLI tool for interacting with Docker

c) A service for orchestrating Docker containers

d) A Docker registry

Answer: a) A GUI tool for managing Docker containers and images



48. What is the command to build a Docker image using a Dockerfile?

a) docker create -f Dockerfile

b) docker build

c) docker run -f Dockerfile

d) docker image create

Answer: b) docker build



49. How do you inspect a running Docker container?

a) docker inspect container_name

b) docker logs container_name

c) docker exec container_name

d) docker status container_name

Answer: a) docker inspect container_name



50. What does the docker info command provide?

a) Information about Docker container logs

b) General information about the Docker installation

c) Details about a specific container

d) Information about Docker volumes

Answer: b) General information about the Docker installation

We have gone through 50 Docker MCQs which would test your understanding of Docker Knowledge. You can also read our other blogs on Basic Python MCQs and How to truncate decimals in Python.