Docker MCQs – Docker Compose

Docker Compose simplifies the management of multi-container applications by allowing you to define and run containers using a single YAML configuration file. It is an essential tool for developers and DevOps engineers working on microservices or containerized environments.

Mastering Docker Compose is crucial for technical interviews, as it demonstrates your ability to manage multi-container setups effectively. These top MCQs cover the foundational and advanced aspects of Docker Compose, ensuring you are well-prepared for interviews and real-world scenarios.

1.) What is Docker Compose used for?

A) Building Docker images
B) Managing container networking
C) Defining and running multi-container Docker applications
D) Debugging Docker containers

Answer: Option C

Explanation: Docker Compose is used to define and run multi-container Docker applications using a YAML file (docker-compose.yml).

2.) What is the default filename for Docker Compose configuration?

A) compose.yaml
B) docker-compose.yml
C) docker.yml
D) compose.json

Answer: Option B

Explanation: The default filename for Docker Compose is docker-compose.yml.

3.) Which command is used to start all services defined in a docker-compose.yml file?

A) docker-compose run
B) docker-compose create
C) docker-compose start
D) docker-compose up

Answer: Option D

Explanation: The docker-compose up command starts all services defined in the docker-compose.yml file.

4.) How do you stop all running services managed by Docker Compose?

A) docker-compose down
B) docker-compose stop
C) docker-compose kill
D) docker-compose terminate

Answer: Option B

Explanation: The docker-compose stop command stops all running services without removing the containers.

5.) Which command removes containers, networks, and volumes created by Docker Compose?

A) docker-compose down
B) docker-compose remove
C) docker-compose destroy
D) docker-compose prune

Answer: Option A

Explanation: The docker-compose down command stops all services and removes the containers, networks, and optionally volumes created by Compose.

6.) What is the purpose of the volumes key in a docker-compose.yml file?

A) To define the storage backend for Docker
B) To link containers
C) To configure network settings
D) To map container storage to the host system

Answer: Option D

Explanation: The volumes key in docker-compose.yml maps storage inside the container to the host system, ensuring data persistence.

7.) Which flag is used with docker-compose up to recreate containers even if they already exist?

A) –force
B) –recreate
C) –build
D) –reset

Answer: Option C

Explanation: The –build flag forces a rebuild of the containers even if they already exist.

8.) How do you execute a command inside a running container managed by Docker Compose?

A) docker exec
B) docker-compose exec
C) docker-compose run
D) docker attach

Answer: Option B

Explanation: The docker-compose exec command runs a command inside a running container managed by Docker Compose.

9.) Which command lists all services defined in a Docker Compose file?

A) docker-compose ps
B) docker-compose ls
C) docker-compose services
D) docker-compose show

Answer: Option A

Explanation: The docker-compose ps command lists all services and their current status.

10.) What is the default network driver used by Docker Compose?

A) Host
B) Bridge
C) Overlay
D) None

Answer: Option B

Explanation: By default, Docker Compose uses the bridge network driver for communication between containers.

Leave a Reply

Your email address will not be published. Required fields are marked *