I am running a docker-compose project in a DigitalOcean Docker droplet.
I also have a persistent volume.
It has been mounted on /mnt/volume_fra1_01
In my docker-compose.yml
, I defined the volume for the database:
...
db:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./postgres/.env
...
volumes:
postgres_data:
...
and I’ve created the symbolic link with sudo ln -s /mnt/volume_fra1_01 postgres_data
But I the database is not persistent. When I purge the containers the database is gone. Somehow /var/lib/postgresql/data/
is not using the mounted volume.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Won’t the postgres data be written to the docker data directory, meaning you would need to pass the full path to
ln
? Something like: