Volume mount fails: path not found
Quick summary
Your container cannot mount a volume — the host path specified in the volume mapping does not exist.
Why this happens
The host directory path in the volume mapping is incorrect or does not exist
The path uses a relative path that resolves differently on the host
Permissions on the host path prevent the container from accessing it
Minimal example
# docker-compose.yml
services:
db:
image: postgres:15
volumes:
- ./data/pg:/var/lib/postgresql/data # ./data/pg does not exist# docker-compose.yml
services:
db:
image: postgres:15
volumes:
- pg_data:/var/lib/postgresql/data # named volume — auto-created
volumes:
pg_data:Using a named volume instead of a bind mount lets Docker auto-create and manage the volume, avoiding path issues.
How to diagnose
Verify the host path exists with ls or test -d on the host machine
Check the volume mapping in docker-compose for correct path syntax
Inspect container logs for mount-related error messages
How to fix
Create the host directory before starting the container: mkdir -p /path/to/dir
Correct the volume mapping path to point to the existing directory
Fix host directory permissions to allow the container user to read and write
How to prevent
Use named volumes instead of bind mounts for container-managed data
Create required host directories in the deployment script before starting containers
Related Resources
Related Lessons
- Container Storage
Learn about volumes.