CompTIA Linux+ (XK0-006)Services and User ManagementMedium

A system administrator is deploying a new web application inside a Docker container. The application needs to persistently store user-uploaded files, and these files must remain accessible even if the container is removed or recreated. Which Docker feature is best suited for this requirement?

  1. ADocker bind mounts
  2. BDocker networks
  3. CDocker volumes
  4. DDocker port mapping
Show answer & explanation

Correct answer: C. Docker volumes

Docker volumes are the preferred mechanism for persisting data generated by and used by Docker containers. They are entirely managed by Docker, isolated from the host filesystem's core functionality, and are designed to persist data even when containers are stopped, removed, or recreated.

Why the other options are wrong

  • A. Docker bind mounts link a host directory directly into a container. While they provide persistence, they expose host filesystem details to containers and are less portable than volumes.
  • B. Docker networks (`--network`) allow containers to communicate with each other and the outside world, but do not provide data persistence.
  • D. Docker port mapping (`-p`) exposes container ports to the host, facilitating network communication, but is unrelated to data persistence.

Docker Volumes

Docker volumes are the recommended way to persist data in Docker. They are fully managed by Docker and stored in a part of the host filesystem (`/var/lib/docker/volumes/`) that is dedicated to Docker.

  • Managed by Docker.
  • Data persists beyond container lifecycle.
  • More portable and secure than bind mounts for general use.

Memory trick: VOLUMES are for persistent Docker data.

More Services and User Management questions