🐳

Docker & Containers MCQ

Test your Docker & Containers knowledge with 100 multiple choice questions covering fundamentals to advanced concepts, with instant feedback and explanations.

100 Questions 40 Beginner 40 Intermediate 20 Advanced
1

What is a Docker container?

2

What is a Docker image?

3

Which command is used to build a Docker image from a Dockerfile?

4

What is the purpose of a Dockerfile?

5

Which command starts a new container from an image?

6

What does the "docker ps" command show?

7

What is the FROM instruction in a Dockerfile used for?

8

What does the Dockerfile instruction "COPY" do?

9

What is the difference between the Dockerfile "CMD" and "ENTRYPOINT" instructions, at a basic level?

10

What does "docker stop" do to a running container?

11

What is the purpose of "docker rm"?

12

What is the purpose of "docker rmi"?

13

What is Docker Hub?

14

What does "docker pull" do?

15

What is the purpose of port mapping with "docker run -p 8080:80"?

16

What does the "-d" flag do when used with "docker run -d"?

17

What is a "volume" in Docker used for?

18

What does "docker exec -it <container> bash" do?

19

What is the default isolation mechanism that allows multiple containers to run on the same host without interfering with each other's processes and filesystems?

20

What is the purpose of a ".dockerignore" file?

21

What does "docker-compose" (or "docker compose") primarily help you do?

22

In a "docker-compose.yml" file, what does the "services" key represent?

23

What is the purpose of the "EXPOSE" instruction in a Dockerfile?

24

What is a "tag" in the context of a Docker image, e.g. "nginx:1.25"?

25

What command shows logs output from a running container?

26

What is the difference between a Docker container and a virtual machine, at a high level?

27

What does the Dockerfile instruction "WORKDIR" do?

28

What does the "docker images" command display?

29

What is the purpose of the "ENV" instruction in a Dockerfile?

30

What happens to data written inside a container's writable layer if the container is removed (without using volumes)?

31

What is the purpose of the "docker network" command?

32

What does the default "bridge" network in Docker provide?

33

What is the purpose of "docker tag"?

34

What does "docker push" do?

35

What is the typical purpose of the "RUN" instruction in a Dockerfile?

36

What is an Alpine-based image, and why is it commonly used as a base image?

37

What does "docker container prune" do?

38

What is the purpose of the "LABEL" instruction in a Dockerfile?

39

Why is it generally recommended to run only one main process per container?

40

What information does "docker inspect <container>" provide?

1

What is a "multi-stage build" in Docker, and why is it useful?

2

What is the difference between a Docker "volume" and a "bind mount"?

3

Why does Docker use a layered filesystem for images, and what benefit does this provide?

4

Why is the ordering of instructions in a Dockerfile important for build performance?

5

What is the purpose of "docker-compose up -d" versus "docker-compose up"?

6

What is the purpose of "healthcheck" configuration in Docker?

7

What does the "depends_on" key in docker-compose.yml control?

8

What is the effect of running a container with "--rm"?

9

What is the purpose of "docker-compose down -v"?

10

How can you limit the amount of memory a container can use?

11

What is the purpose of "ARG" in a Dockerfile, and how does it differ from "ENV"?

12

What does "docker system prune -a" do, and why should it be used carefully?

13

What is the purpose of naming a Docker network and attaching multiple containers to it (instead of using the default bridge)?

14

What does it mean for a Docker image layer to be "cached", and what invalidates that cache during a rebuild?

15

What is the difference between "CMD [\"executable\", \"param\"]" (exec form) and "CMD executable param" (shell form) in a Dockerfile?

16

How does "docker-compose" handle environment-specific configuration, e.g. using multiple compose files?

17

What is the purpose of "docker cp"?

18

Why might "RUN apt-get update && apt-get install -y <package>" be written on a single RUN line rather than two separate RUN lines?

19

What is a "named volume" in Docker, and how does it differ from an anonymous volume?

20

What does "docker stats" provide?

21

What problem does setting a non-root "USER" instruction in a Dockerfile address?

22

What is the purpose of an "init" system or "tini" in some Docker containers?

23

How 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?

24

What does the "--network host" option do when running a container?

25

What is the purpose of "docker volume create" with a specified driver, e.g. for cloud storage?

26

What does "restart: unless-stopped" mean in a docker-compose service definition?

27

Why might you use "COPY --from=<stage>" in a multi-stage Dockerfile?

28

What is the difference between "docker stop" and "docker kill"?

29

What is the purpose of "docker-compose.override.yml"?

30

What does "docker build --no-cache" do, and when might it be needed?

31

What is the significance of the "PID 1" process inside a container regarding "docker stop"?

32

What does the ".env" file do in a docker-compose project by default?

33

Why might a containerized application behave differently regarding available memory than expected, even with "--memory" not set?

34

What is the purpose of "docker save" and "docker load"?

35

What is the role of "buildkit" in modern Docker builds?

36

What is the difference between scaling a service with "docker-compose up --scale web=3" and defining 3 separate services in the compose file?

37

What is the purpose of "docker logout" and credential storage when working with private registries?

38

What does "docker run --env-file <file>" allow you to do?

39

Why might you use "docker-compose config" before running "docker-compose up"?

40

What is the effect of setting "read_only: true" for a service in docker-compose?

1

How do Linux namespaces contribute to container isolation, and name at least the type that isolates process IDs?

2

What is the purpose of "cgroups" (control groups) in the context of Docker, distinct from namespaces?

3

What is the difference between the "overlay2" storage driver and using bind mounts for a container's root filesystem?

4

What 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"?

5

What does "docker exec" rely on internally to enter a running container's namespaces, and how does this differ conceptually from starting a new container?

6

What is "container escape", and what are common mitigations?

7

What does the "--cap-add" and "--cap-drop" flags control, and why might dropping capabilities improve security?

8

How does Docker's "seccomp" default profile improve container security?

9

What is the significance of "OCI" (Open Container Initiative) specifications for the Docker ecosystem?

10

Why 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?

11

How does Docker's default bridge network differ from user-defined bridge networks regarding inter-container communication, particularly around "--link" (legacy) versus modern approaches?

12

What is the purpose of "docker manifest" and manifest lists in supporting multi-architecture images?

13

Why might setting "ulimits" be necessary for certain containerized applications, and what is an example of a ulimit relevant to containers?

14

What does "docker build --secret" address, and what problem does it solve compared to using "ARG" for sensitive values like API keys?

15

What is the difference between "docker run --restart=always" and an orchestrator (like Kubernetes or Swarm) restarting a failed container?

16

How does the choice of base image affect the security and size trade-offs of a production image, particularly regarding "distroless" images?

17

What is "BuildKit's" cache mount feature (e.g. "RUN --mount=type=cache,target=/root/.cache") used for?

18

Why is pinning exact image digests (e.g. "FROM node@sha256:abcd...") sometimes preferred over tags like "FROM node:20" in production Dockerfiles?

19

What does "docker events" allow you to do, and how might it be used in monitoring or automation?

20

In 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?