Docker MCQs – Docker Containers

11.) How do you name a container when running it?

A) Using the -t flag
B) By renaming the Dockerfile
C) Using the –id flag
D) Using the –name flag

Answer: Option D

Explanation: The –name flag assigns a custom name to the container.

12.) How do you inspect detailed information about a container?

A) docker inspect <container-id>
B) docker logs <container-id>
C) docker history <container-id>
D) docker ps –detail

Answer: Option A

Explanation: The docker inspect command provides detailed information about a container’s configuration and state.

13.) What is the purpose of container ports in Docker?

A) To provide persistent storage
B) To enable network communication between the container and host
C) To run multiple containers in parallel
D) To debug the container

Answer: Option B

Explanation: Container ports enable network communication between the container and the host system.

14.) Which command removes all stopped containers?

A) docker rm all
B) docker container prune
C) docker clean
D) docker rm –all

Answer: Option B

Explanation: The docker container prune command removes all stopped containers from the system.

15.) How do you limit CPU usage for a container?

A) –limit-cpu
B) –cpu-share
C) –cpus
D) –cpu-limit

Answer: Option C

Explanation: The –cpus flag specifies the maximum CPU usage for a container.

16.) How do you limit memory usage for a container?

A) –memory
B) –mem-limit
C) –limit-mem
D) –ram

Answer: Option A

Explanation: The –memory flag limits the memory available to a container.

17.) What happens if you try to remove a running container?

A) The container is forcefully stopped and removed.
B) Docker throws an error.
C) The container is removed without stopping it.
D) Docker archives the container.

Answer: Option B

Explanation: Docker throws an error if you try to remove a running container without stopping it first.

18.) How do you forcefully remove a running container?

A) docker rm -f <container-id>
B) docker stop <container-id>
C) docker terminate <container-id>
D) docker remove –force <container-id>

Answer: Option A

Explanation: The -f flag with docker rm forcefully removes a running container.

19.) Which command displays container resource usage statistics?

A) docker logs
B) docker monitor
C) docker inspect
D) docker stats

Answer: Option D

Explanation: The docker stats command displays real-time resource usage statistics for running containers.

20.) How do you pause a running container?

A) docker pause <container-id>
B) docker stop <container-id>
C) docker hold <container-id>
D) docker freeze <container-id>

Answer: Option A

Explanation: The docker pause command pauses all processes in a container.

Leave a Reply

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