Docker MCQs – Docker Containers

Docker containers are the runtime instances of Docker images, encapsulating applications and their dependencies in lightweight, portable environments. Containers are the cornerstone of Docker and enable consistent application behavior across development, testing, and production.

Mastering Docker containers is essential for technical interviews, as they frequently focus on container creation, management, and optimization. These top MCQs are designed to test your knowledge and prepare you for real-world scenarios and interview challenges.

1.) What is a Docker container?

A) A virtual machine
B) A runtime instance of a Docker image
C) A tool for building Docker images
D) A Docker registry

Answer: Option B

Explanation: A Docker container is a runtime instance of a Docker image that includes the application and its dependencies.

2.) Which command is used to create and start a container?

A) docker start
B) docker create
C) docker run
D) docker init

Answer: Option C

Explanation: The docker run command is used to create and start a container in one step.

3.) How do you list all running containers?

A) docker list
B) docker show
C) docker containers
D) docker ps

Answer: Option D

Explanation: The docker ps command lists all running containers.

4.) How do you stop a running Docker container?

A) docker stop <container-id>
B) docker end <container-id>
C) docker terminate <container-id>
D) docker pause <container-id>

Answer: Option A

Explanation: The docker stop command stops a running container.

5.) Which command is used to remove a container?

A) docker rm <container-id>
B) docker delete <container-id>
C) docker remove <container-id>
D) docker rmi <container-id>

Answer: Option A

Explanation: The docker rm command is used to remove a container from your Docker environment. This command deletes the container’s filesystem and metadata, effectively removing it from the Docker host.

6.) How can you view the logs of a container?

A) docker view <container-id>
B) docker inspect <container-id>
C) docker logs <container-id>
D) docker history <container-id>

Answer: Option C

Explanation: The docker logs command is used to view the logs of a running or stopped container. This command helps you inspect the output and any errors that the container might have produced during its execution.

7.) What happens to a container if it is stopped and not removed?

A) It is automatically deleted.
B) It remains on the system and can be restarted.
C) It is moved to an archive.
D) It cannot be restarted.

Answer: Option B

Explanation: When a container is stopped but not removed, it remains on the system in a stopped state. You can restart the container using the docker start command whenever needed.

8.) How can you restart a stopped container?

A) docker init <container-id>
B) docker restart <container-id>
C) docker start <container-id>
D) docker run <container-id>

Answer: Option C

Explanation: The docker start command is used to restart a stopped container. If the container was previously stopped, using this command will start it again from where it left off.

9.) Which flag is used to run a container in detached mode?

A) -i
B) -d
C) –detach
D) Both B and C

Answer: Option D

Explanation: Both -d and –detach flags run a container in detached mode, allowing it to run in the background.

10.) What does the -it flag do in the docker run command?

A) Runs the container in detached mode
B) Allocates a pseudo-TTY and keeps the container interactive
C) Runs multiple containers simultaneously
D) Specifies the image tag to use

Answer: Option B

Explanation: The -it flag allocates a pseudo-TTY and keeps the container interactive, allowing user input.

Leave a Reply

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