Docker & Containers MCQ
Test your Docker & Containers knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.
What is a Docker container?
2What is a Docker image?
3Which command is used to build a Docker image from a Dockerfile?
4What is the purpose of a Dockerfile?
5Which command starts a new container from an image?
6What does the "docker ps" command show?
7What is the FROM instruction in a Dockerfile used for?
8What does the Dockerfile instruction "COPY" do?
9What is the difference between the Dockerfile "CMD" and "ENTRYPOINT" instructions, at a basic level?
10What does "docker stop" do to a running container?
11What is the purpose of "docker rm"?
12What is the purpose of "docker rmi"?
13What is Docker Hub?
14What does "docker pull" do?
15What is the purpose of port mapping with "docker run -p 8080:80"?
16What does the "-d" flag do when used with "docker run -d"?
17What is a "volume" in Docker used for?
18What does "docker exec -it <container> bash" do?
19What is the default isolation mechanism that allows multiple containers to run on the same host without interfering with each other's processes and filesystems?
20What is the purpose of a ".dockerignore" file?
21What does "docker-compose" (or "docker compose") primarily help you do?
22In a "docker-compose.yml" file, what does the "services" key represent?
23What is the purpose of the "EXPOSE" instruction in a Dockerfile?
24What is a "tag" in the context of a Docker image, e.g. "nginx:1.25"?
25What command shows logs output from a running container?
26What is the difference between a Docker container and a virtual machine, at a high level?
27What does the Dockerfile instruction "WORKDIR" do?
28What does the "docker images" command display?
29What is the purpose of the "ENV" instruction in a Dockerfile?
30What happens to data written inside a container's writable layer if the container is removed (without using volumes)?
31What is the purpose of the "docker network" command?
32What does the default "bridge" network in Docker provide?
33What is the purpose of "docker tag"?
34What does "docker push" do?
35What is the typical purpose of the "RUN" instruction in a Dockerfile?
36What is an Alpine-based image, and why is it commonly used as a base image?
37What does "docker container prune" do?
38What is the purpose of the "LABEL" instruction in a Dockerfile?
39Why is it generally recommended to run only one main process per container?
40What information does "docker inspect <container>" provide?
What is a "multi-stage build" in Docker, and why is it useful?
2What is the difference between a Docker "volume" and a "bind mount"?
3Why does Docker use a layered filesystem for images, and what benefit does this provide?
4Why is the ordering of instructions in a Dockerfile important for build performance?
5What is the purpose of "docker-compose up -d" versus "docker-compose up"?
6What is the purpose of "healthcheck" configuration in Docker?
7What does the "depends_on" key in docker-compose.yml control?
8What is the effect of running a container with "--rm"?
9What is the purpose of "docker-compose down -v"?
10How can you limit the amount of memory a container can use?
11What is the purpose of "ARG" in a Dockerfile, and how does it differ from "ENV"?
12What does "docker system prune -a" do, and why should it be used carefully?
13What is the purpose of naming a Docker network and attaching multiple containers to it (instead of using the default bridge)?
14What does it mean for a Docker image layer to be "cached", and what invalidates that cache during a rebuild?
15What is the difference between "CMD [\"executable\", \"param\"]" (exec form) and "CMD executable param" (shell form) in a Dockerfile?
16How does "docker-compose" handle environment-specific configuration, e.g. using multiple compose files?
17What is the purpose of "docker cp"?
18Why might "RUN apt-get update && apt-get install -y <package>" be written on a single RUN line rather than two separate RUN lines?
19What is a "named volume" in Docker, and how does it differ from an anonymous volume?
20What does "docker stats" provide?
21What problem does setting a non-root "USER" instruction in a Dockerfile address?
22What is the purpose of an "init" system or "tini" in some Docker containers?
23How does Docker determine which platform/architecture (e.g. amd64 vs arm64) an image is built for, and why does this matter for multi-platform builds?
24What does the "--network host" option do when running a container?
25What is the purpose of "docker volume create" with a specified driver, e.g. for cloud storage?
26What does "restart: unless-stopped" mean in a docker-compose service definition?
27Why might you use "COPY --from=<stage>" in a multi-stage Dockerfile?
28What is the difference between "docker stop" and "docker kill"?
29What is the purpose of "docker-compose.override.yml"?
30What does "docker build --no-cache" do, and when might it be needed?
31What is the significance of the "PID 1" process inside a container regarding "docker stop"?
32What does the ".env" file do in a docker-compose project by default?
33Why might a containerized application behave differently regarding available memory than expected, even with "--memory" not set?
34What is the purpose of "docker save" and "docker load"?
35What is the role of "buildkit" in modern Docker builds?
36What is the difference between scaling a service with "docker-compose up --scale web=3" and defining 3 separate services in the compose file?
37What is the purpose of "docker logout" and credential storage when working with private registries?
38What does "docker run --env-file <file>" allow you to do?
39Why might you use "docker-compose config" before running "docker-compose up"?
40What is the effect of setting "read_only: true" for a service in docker-compose?
How do Linux namespaces contribute to container isolation, and name at least the type that isolates process IDs?
2What is the purpose of "cgroups" (control groups) in the context of Docker, distinct from namespaces?
3What is the difference between the "overlay2" storage driver and using bind mounts for a container's root filesystem?
4What security concern arises from mounting the Docker socket ("/var/run/docker.sock") into a container, and why is this sometimes called "Docker-in-Docker via socket mounting"?
5What does "docker exec" rely on internally to enter a running container's namespaces, and how does this differ conceptually from starting a new container?
6What is "container escape", and what are common mitigations?
7What does the "--cap-add" and "--cap-drop" flags control, and why might dropping capabilities improve security?
8How does Docker's "seccomp" default profile improve container security?
9What is the significance of "OCI" (Open Container Initiative) specifications for the Docker ecosystem?
10Why can excessive image layers (from many separate RUN/COPY instructions) negatively affect both image size and build performance, and how do multi-stage builds and combining commands address this?
11How does Docker's default bridge network differ from user-defined bridge networks regarding inter-container communication, particularly around "--link" (legacy) versus modern approaches?
12What is the purpose of "docker manifest" and manifest lists in supporting multi-architecture images?
13Why might setting "ulimits" be necessary for certain containerized applications, and what is an example of a ulimit relevant to containers?
14What does "docker build --secret" address, and what problem does it solve compared to using "ARG" for sensitive values like API keys?
15What is the difference between "docker run --restart=always" and an orchestrator (like Kubernetes or Swarm) restarting a failed container?
16How does the choice of base image affect the security and size trade-offs of a production image, particularly regarding "distroless" images?
17What is "BuildKit's" cache mount feature (e.g. "RUN --mount=type=cache,target=/root/.cache") used for?
18Why is pinning exact image digests (e.g. "FROM node@sha256:abcd...") sometimes preferred over tags like "FROM node:20" in production Dockerfiles?
19What does "docker events" allow you to do, and how might it be used in monitoring or automation?
20In a CI/CD pipeline, why might "docker build" results vary between runs even with an identical Dockerfile and source code, and what techniques help ensure reproducibility?