Linux+ Linux+ Container Operations with Docker 3 — Questions and Answers
Question 1: A container is running but needs to be stopped gracefully. Which signal does docker stop send by default before force-killing the process?
- SIGKILL
- SIGTERM (Correct answer)
- SIGHUP
- SIGINT
Correct answer: SIGTERM
docker stop sends SIGTERM first, giving the process time to shut down cleanly, then sends SIGKILL after a timeout (default 10 seconds).
Question 2: Which Dockerfile instruction is used to define the default working directory for subsequent RUN, CMD, ENTRYPOINT, COPY, and ADD instructions?
- CD
- WORKDIR (Correct answer)
- PATH
- DIR
Correct answer: WORKDIR
WORKDIR sets the working directory inside the container image and creates it if it does not exist.
Question 3: What does the --read-only flag do when passed to docker run?
- Mounts the host filesystem as read-only inside the container
- Makes the container's root filesystem read-only, preventing writes (Correct answer)
- Pulls the image without caching it locally
- Prevents other users from inspecting the container
Correct answer: Makes the container's root filesystem read-only, preventing writes
The --read-only flag mounts the container's root filesystem as read-only, improving security by preventing unauthorized file modifications.
Question 4: A Linux administrator wants containers on two different Docker hosts to communicate. Which network driver should be used?
- bridge
- host
- overlay (Correct answer)
- none
Correct answer: overlay
Overlay networks span multiple Docker hosts using VXLAN encapsulation and require a key-value store like etcd or Consul for coordination.
Question 5: What happens to container data stored in a named volume when the container is deleted with docker rm?
- The volume is deleted automatically along with the container
- The volume persists and must be removed separately with docker volume rm (Correct answer)
- The volume is compressed and archived to /var/lib/docker
- The data is copied to the host's home directory
Correct answer: The volume persists and must be removed separately with docker volume rm
Named volumes have an independent lifecycle from containers; deleting a container does not remove its associated named volumes.
Question 6: Which command shows the layer history and build commands used to create a Docker image?
- docker inspect --layers
- docker history (Correct answer)
- docker image log
- docker layers --show
Correct answer: docker history
docker history displays each layer of an image, its size, and the instruction that created it.
Question 7: When using docker run -p 8080:80, what does port 8080 represent?
- The container's internal listening port
- The host machine's port that maps to the container (Correct answer)
- The Docker daemon's management port
- The image's default exposed port
Correct answer: The host machine's port that maps to the container
In -p host_port:container_port format, 8080 is the host port that forwards traffic to port 80 inside the container.
A container is running but needs to be stopped gracefully.
Which signal does docker stop send by default before force-killing the process?