postgresqldockerdocker-volume

docker postgres named volume is never populated


I have a docker Postgres container which uses a named volume for persistence. The container starts and runs without errors using docker-compose. But the named volume is never populated. The size is always 0. And when I remove the container, all data is lost. The database in the container is populated (PGADMIN, restore of dump). After the restore of the dump the command "select pg_database_size('db_finance');" shows a size of 1.1571 gb

What could be the reason that the volume is never populated?

# docker-compose.yaml

services:
  postgres:
    container_name: database
    image: postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d db_finance"]
      interval: 10s
      retries: 5
      start_period: 30s
      timeout: 10s
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=db_finance
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=passw
    volumes:
      - pgdata:/var/lib/postgresql/data

volumes:
  pgdata:

docker system df -v

enter image description here

The database size:

enter image description here


Solution

  • When executing the command "docker volume list", I noticed that there were a few other volumes present. I then did a "docker-compose down" and then a "docker volume prune" which got rid of unused volumes. Then I restarted all containers with "docker-compose up -d" , and now there was only one volume left. After a restore with PGADMIN, the volume was populated.

    So, somehow docker was mixing up volumes. Getting rid of all volumes solved the problem.

    enter image description here