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

A system administrator is deploying a new web application that runs inside a Docker container. The application needs to persistently store its data in a directory on the host machine, `/srv/myapp/data`, and this directory should be accessible to the container at `/app/data`. The container image is `mywebapp:latest`. Which `docker run` command option correctly configures this persistent storage?

  1. A--mount type=volume,source=/srv/myapp/data,target=/app/data
  2. B--link /srv/myapp/data:/app/data
  3. C-e /srv/myapp/data:/app/data
  4. D-v /srv/myapp/data:/app/data
Show answer & explanation

Correct answer: D. -v /srv/myapp/data:/app/data

The `-v` (or `--volume`) option is the standard and most common way to create a bind mount in Docker, mapping a host directory to a path inside the container. The syntax is `host_path:container_path`.

Why the other options are wrong

  • A. `--mount` is a more verbose and newer syntax for mounting, but for bind mounts, it should be `type=bind` not `type=volume`. `type=volume` would create a named Docker volume.
  • B. `--link` is a deprecated option used for linking containers to each other, not for mounting host directories.
  • C. `-e` is used to set environment variables inside the container, not for mounting volumes.

Docker Bind Mount

A Docker bind mount allows a directory or file on the host machine to be mounted directly into a container, providing persistent storage that is managed by the host's filesystem.

  • Uses `-v host_path:container_path` or `--mount type=bind,source=host_path,target=container_path`.
  • Data persists even if the container is removed.
  • Host path must exist for the bind mount to work correctly.

Memory trick: Docker needs mounts to make data last.

More Services and User Management questions