MCQs Questions on Managing Containers | Docker Multiple Choice Questions

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

  1. Which command is used to create and start a container in Docker?
    a) docker build
    b) docker run
    c) docker create
    d) docker start
  2. 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
  3. 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
  4. Which command allows you to limit the CPU usage of a container?
    a) --cpu-limit
    b) --cpus
    c) --limit-cpu
    d) --cpu-usage
  5. 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
  6. How do you specify an environment variable while starting a container?
    a) --env
    b) --variable
    c) --set-env
    d) --environment
  7. Which option allows you to bind a host directory to a container directory?
    a) --mount
    b) --bind
    c) --volume
    d) --storage
  8. What is the default network mode for a Docker container?
    a) Host
    b) Bridge
    c) None
    d) Overlay
  9. Which flag ensures a container is removed after it stops?
    a) --cleanup
    b) --remove
    c) --rm
    d) --autoremove
  10. 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

  1. Which command is used to inspect container metadata?
    a) docker view
    b) docker inspect
    c) docker info
    d) docker metadata
  2. How can you view the logs of a running container?
    a) docker logs
    b) docker view-logs
    c) docker read
    d) docker output
  3. 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
  4. Which flag can be used to view real-time logs of a container?
    a) --live
    b) --follow
    c) --stream
    d) --realtime
  5. 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
  6. Which of the following commands shows the container’s running status?
    a) docker run-status
    b) docker inspect
    c) docker ps
    d) docker status
  7. 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
  8. How do you check the resource usage of a running container?
    a) docker stats
    b) docker inspect --resources
    c) docker monitor
    d) docker usage
  9. 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
  10. 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)

  1. What is the default network driver in Docker?
    a) None
    b) Bridge
    c) Host
    d) Overlay
  2. Which network mode allows containers to share the host’s network stack?
    a) None
    b) Bridge
    c) Host
    d) Overlay
  3. 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
  4. 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
  5. 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

  1. 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
  2. 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
  3. 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
  4. How do you attach a volume to a container?
    a) --volume
    b) --attach
    c) --storage
    d) --bind
  5. 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

QnoAnswer (Option with Text)
1b) docker run
2b) To run the container in the background
3c) It defaults to the “latest” tag
4b) --cpus
5c) No restart policy
6a) --env
7c) --volume
8b) Bridge
9c) --rm
10b) docker pull
11b) docker inspect
12a) docker logs
13b) Only running containers
14b) --follow
15b) Use grep with docker logs
16c) docker ps
17c) /var/lib/docker/containers
18a) docker stats
19d) --log-opt max-size
20a) To monitor system-wide Docker events
21b) Bridge
22c) Host
23b) Assigns a specific network to the container
24b) It has no network access
25c) docker network create
26b) To persist data outside the container’s lifecycle
27c) docker volume ls
28b) docker volume prune
29a) --volume
30a) /var/lib/docker/volumes

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top