Question

Persistent database with docker-compose not working

Posted June 23, 2021 108 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:

...

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.

Submit an answer

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