docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.2k stars 1.14k forks source link

Volume mapping resets every compose #1289

Closed RampantDespair closed 3 days ago

RampantDespair commented 3 days ago

As the title states, every time I docker compose up/down, a new volume is created. This causes a few issues on my end notably the loss of my previous data.

Despite having the following set in my docker-compose.yaml

# Postgres
  postgres:
    image: postgres:latest
    container_name: postgres
    hostname: postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgres
    ports:
      - "3001:5432"
    networks:
      - backend_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -d postgres -U ${POSTGRES_USER}"]
      interval: 3s
      timeout: 3s
      retries: 5

In practice I get this image

And the postgres_data volume is completely empty image

Surely this is an error on my end and not the expected behavior? I'm semi-new to docker so if someone could point me in the right direction that would be much appreciated!

RampantDespair commented 3 days ago

Issue was resolved reading this: https://stackoverflow.com/questions/41637505/how-to-persist-data-in-a-dockerized-postgres-database-using-volumes