Description
A bind mount exposes a host path to the container. A broad path can expose backups, system configuration or production data the service does not need.
A path listed on its own under a service’s volumes is the container destination of an anonymous volume. A named volume can specify a host path in driver_opts even if no service uses it. Inspect the volume definition in the Compose file and use docker compose config to check which services reference it.
Potential impact
The service can read files its user can access. A writable mount can also let it change or delete them.
Remediation
Mount only the required files or a dedicated directory. Give readers a read-only mount using :ro or the long-syntax mount option read_only: true. They can still read sensitive data under that path.
Examples
Use your backup image in place of backup-service.
Before
version: "3.9"
services:
backup:
image: backup-service
volumes:
- /var/lib/backup/data:/data
The example mounts /var/lib/backup/data at /data with the default read-write access.
After
version: "3.9"
services:
backup:
image: backup-service
volumes:
- backup-data:/data
volumes:
backup-data:
Switching to the named volume backup-data changes where /data is stored. Migrate existing backups, set permissions and test backup and restore before switching over.