Docker MCQs – Docker Compose

11.) How do you specify environment variables in a Docker Compose file?

A) Using the env key
B) Using the variables key
C) Using the environment key
D) Using the config key

Answer: Option C

Explanation: The environment key in docker-compose.yml is used to define environment variables for services.

12.) Which command updates a running service in Docker Compose?

A) docker-compose redeploy
B) docker-compose update
C) docker-compose restart
D) docker-compose up

Answer: Option D

Explanation: Running docker-compose up updates services if changes are detected in the docker-compose.yml file.

13.) How can you scale a service using Docker Compose?

A) By adding replicas in docker-compose.yml
B) Using the docker-compose scale command
C) Using the –replicas flag with docker-compose up
D) Both A and B

Answer: Option D

Explanation: Services can be scaled by adding replicas in docker-compose.yml or using the docker-compose scale command.

14.) Which key in the docker-compose.yml file is used to specify dependencies between services?

A) depends_on
B) links
C) volumes
D) networks

Answer: Option A

Explanation: The depends_on key specifies the order in which services should start based on dependencies.

15.) How do you override the default docker-compose.yml file?

A) By renaming the file
B) By creating a docker-override.yml file
C) Using the -f flag with docker-compose commands
D) Using the –override flag

Answer: Option C

Explanation: The -f flag is used to specify an alternative Compose file to override the default docker-compose.yml.

16.) How do you define custom networks in Docker Compose?

A) Under the networks key in docker-compose.yml
B) Using the docker network create command
C) By defining them in the container
D) Automatically generated by Compose

Answer: Option A

Explanation: Custom networks can be defined under the networks key in the docker-compose.yml file.

17.) What is the purpose of the restart key in Docker Compose?

A) To automatically rebuild the container
B) To define the restart policy for containers
C) To enable scaling of services
D) To restart the Docker service

Answer: Option B

Explanation: The restart key defines the restart policy for containers (e.g., always, on-failure, or no).

18.) Which command lists the logs of all services in Docker Compose?

A) docker-compose logs
B) docker-compose show
C) docker-compose status
D) docker-compose events

Answer: Option A

Explanation: The docker-compose logs command displays the logs of all services defined in the Compose file.

19.) How do you remove orphaned containers created by Docker Compose?

A) docker-compose clean
B) docker-compose prune
C) docker-compose down –remove-orphans
D) docker-compose rm -orphans

Answer: Option C

Explanation: The docker-compose down –remove-orphans command removes containers that are no longer defined in the Compose file.

20.) How do you build all services defined in a Compose file?

A) docker-compose create
B) docker-compose build
C) docker-compose compile
D) docker-compose prepare

Answer: Option B

Explanation: The docker-compose build command builds all services defined in the docker-compose.yml file.

Leave a Reply

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