Persistent database with docker-compose not working

Posted June 23, 2021 407 views
DockerDigitalOcean Volumes

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:


    image: postgres:12.0-alpine
      - postgres_data:/var/lib/postgresql/data/
      - ./postgres/.env




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.

Submit an Answer
1 answer

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:

sudo ln -s /mnt/volume_fra1_01 /var/lib/docker/postgres_data/_data