Docker Compose PostgreSQL Data Persistence Not Working as Expected

'm having trouble with data persistence in my Docker Compose setup for a Spring Boot application that uses PostgreSQL. The data persists only when I stop the PostgreSQL container individually and start it again, but when I bring the entire Docker Compose stack down and then up again, the data is lost. Here’s my docker-compose.yml file:

Hi, Add a docker-compose file if the question is actual.

Have you created a volume and added that to your docker-compose file.

For example, the following is minimal just to show.

Create a volume:

From my docker-compose here is a snippet from the service section for postgres part.

      - 5433:5432
      - pg1-1-node1-data:/pgdata
    hostname: pg1-1-node1
    container_name: pg1-1-node1

Then further down in the volumes sectio

1 Like