Linux+ Linux+ Container Operations with Docker 2 — Questions and Answers
Question 1: Which Docker command displays real-time resource usage statistics for all running containers?
- docker inspect --live
- docker stats (Correct answer)
- docker top --all
- docker monitor
Correct answer: docker stats
docker stats streams live CPU, memory, network I/O, and block I/O metrics for running containers.
Question 2: What does the Docker instruction ENTRYPOINT do differently than CMD in a Dockerfile?
- ENTRYPOINT sets environment variables; CMD runs a script
- ENTRYPOINT defines the executable that cannot be overridden by docker run arguments; CMD provides defaults that can be overridden (Correct answer)
- ENTRYPOINT copies files into the image; CMD exposes ports
- ENTRYPOINT and CMD are functionally identical
Correct answer: ENTRYPOINT defines the executable that cannot be overridden by docker run arguments; CMD provides defaults that can be overridden
ENTRYPOINT sets the fixed executable for the container, while CMD arguments can be replaced by passing arguments to docker run.
Question 3: A developer needs to pass a build-time variable to a Dockerfile during docker build. Which instruction should be used?
- ENV
- ARG (Correct answer)
- SET
- PARAM
Correct answer: ARG
ARG declares a variable that users can pass at build-time with --build-arg, unlike ENV which sets runtime environment variables.
Question 4: Which command removes all stopped containers, unused networks, dangling images, and build cache?
- docker rm --all
- docker clean
- docker system prune (Correct answer)
- docker purge --force
Correct answer: docker system prune
docker system prune is a bulk cleanup command that reclaims disk space by removing all unused Docker objects.
Question 5: When using docker cp, what is the correct syntax to copy a file from a running container to the host?
- docker cp host_path container_name:container_path
- docker cp container_name:container_path host_path (Correct answer)
- docker copy --from=container_name container_path host_path
- docker pull container_name:file_path
Correct answer: docker cp container_name:container_path host_path
docker cp uses container_name:path as the source and host path as destination when copying from a container to the host.
Question 6: Which Docker networking mode allows a container to share the host machine's network stack directly?
- bridge
- overlay
- host (Correct answer)
- macvlan
Correct answer: host
Host network mode removes network isolation between container and host, making the container use the host's IP and ports directly.
Question 7: What is the purpose of a Docker multi-stage build?
- To run multiple containers simultaneously in one Dockerfile
- To create separate production and development images automatically
- To reduce final image size by copying only needed artifacts from earlier build stages (Correct answer)
- To enable parallel execution of RUN instructions
Correct answer: To reduce final image size by copying only needed artifacts from earlier build stages
Multi-stage builds use multiple FROM instructions so only compiled artifacts are copied into the final lightweight image, discarding build tools.
Which Docker command displays real-time resource usage statistics for all running containers?