Persistent database with docker-compose not working

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.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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