Docker revolutionizes application deployment with lightweight, portable containers. Mastering container management is essential for developers and administrators. These Docker MCQ questions and answers cover creating, running, inspecting, logging containers, understanding networking basics (bridge, host, none), volumes, persistent storage, and managing container lifecycles. Sharpen your Docker skills now!
Docker MCQs: Managing Containers
Creating and Running Containers
Which command is used to create and start a container in Docker? a) docker build b) docker run c) docker create d) docker start
What is the primary purpose of the --detach or -d option when running a container? a) To attach the container to a debugger b) To run the container in the background c) To stop the container after execution d) To remove the container after execution
What happens if you run a Docker container without specifying a tag for the image? a) It defaults to the “stable” tag b) It throws an error c) It defaults to the “latest” tag d) It uses a random tag
Which command allows you to limit the CPU usage of a container? a) --cpu-limit b) --cpus c) --limit-cpu d) --cpu-usage
What is the default restart policy for a Docker container? a) Always restart b) Restart unless stopped c) No restart policy d) Restart on failure
How do you specify an environment variable while starting a container? a) --env b) --variable c) --set-env d) --environment
Which option allows you to bind a host directory to a container directory? a) --mount b) --bind c) --volume d) --storage
What is the default network mode for a Docker container? a) Host b) Bridge c) None d) Overlay
Which flag ensures a container is removed after it stops? a) --cleanup b) --remove c) --rm d) --autoremove
How do you pull an image before running a container explicitly? a) docker fetch b) docker pull c) docker load d) docker download
Inspecting and Logging Containers
Which command is used to inspect container metadata? a) docker view b) docker inspect c) docker info d) docker metadata
How can you view the logs of a running container? a) docker logs b) docker view-logs c) docker read d) docker output
What does the docker ps command display? a) All containers (running and stopped) b) Only running containers c) Container logs d) System-wide resource usage
Which flag can be used to view real-time logs of a container? a) --live b) --follow c) --stream d) --realtime
How can you filter logs for specific keywords in Docker? a) docker logs --filter b) Use grep with docker logs c) docker logs --keyword d) Docker does not support filtering logs
Which of the following commands shows the container’s running status? a) docker run-status b) docker inspect c) docker ps d) docker status
Where are container logs stored by default on a Docker host? a) /var/lib/docker/logs b) /var/log/docker/containers c) /var/lib/docker/containers d) /var/docker/host
How do you check the resource usage of a running container? a) docker stats b) docker inspect --resources c) docker monitor d) docker usage
Which flag helps to limit the log size for a container? a) --log-max b) --log-size c) --max-log-size d) --log-opt max-size
What is the purpose of docker events? a) To monitor system-wide Docker events b) To display detailed logs of a container c) To list recent container activities d) To show startup events of a container
Networking Basics (Bridge, Host, None)
What is the default network driver in Docker? a) None b) Bridge c) Host d) Overlay
Which network mode allows containers to share the host’s network stack? a) None b) Bridge c) Host d) Overlay
What does the --network flag do when running a container? a) Specifies the container’s DNS settings b) Assigns a specific network to the container c) Disconnects the container from all networks d) Enables port forwarding
What happens if you run a container with the “none” network mode? a) It uses the default bridge network b) It has no network access c) It shares the host’s network stack d) It creates an isolated overlay network
How do you create a new Docker network? a) docker network init b) docker create-network c) docker network create d) docker add-network
Volumes and Persistent Storage
What is the primary purpose of Docker volumes? a) To speed up container builds b) To persist data outside the container’s lifecycle c) To replicate data between containers d) To store logs
How do you list all Docker volumes on a host? a) docker volumes b) docker volume list c) docker volume ls d) docker list-volumes
Which command is used to remove unused Docker volumes? a) docker volume delete-unused b) docker volume prune c) docker volume remove-unused d) docker volume clean
How do you attach a volume to a container? a) --volume b) --attach c) --storage d) --bind
Where are Docker volumes stored by default on a host? a) /var/lib/docker/volumes b) /usr/local/docker/volumes c) /etc/docker/volumes d) /var/docker/data
Answer Key
Qno
Answer (Option with Text)
1
b) docker run
2
b) To run the container in the background
3
c) It defaults to the “latest” tag
4
b) --cpus
5
c) No restart policy
6
a) --env
7
c) --volume
8
b) Bridge
9
c) --rm
10
b) docker pull
11
b) docker inspect
12
a) docker logs
13
b) Only running containers
14
b) --follow
15
b) Use grep with docker logs
16
c) docker ps
17
c) /var/lib/docker/containers
18
a) docker stats
19
d) --log-opt max-size
20
a) To monitor system-wide Docker events
21
b) Bridge
22
c) Host
23
b) Assigns a specific network to the container
24
b) It has no network access
25
c) docker network create
26
b) To persist data outside the container’s lifecycle