Skip to content

Postgre compose.yml creates two volumes instead of one #122

@viadezo1er

Description

@viadezo1er

I also found a fix, see most recent PR.

Describe the bug

Postgre docker compose creates a useless volume (random name like 998e1a214a2ab50ce098dc9bda4952e65e48b524f055ee5192fcafd7052b3f09) that can be pruned after container has started.
Data does not persist after docker compose down.

To Reproduce
Steps to reproduce the behavior:
With this compose.yml:

services:
  postgres:
    image: postgres:18-alpine
    container_name: postgres-db
    restart: unless-stopped
    environment:
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypassword
      POSTGRES_DB: mydb
    ports:
      - "5432:5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data

volumes:
  postgres-data:
docker compose up
docker volume ls
DRIVER    VOLUME NAME
local     998e1a214a2ab50ce098dc9bda4952e65e48b524f055ee5192fcafd7052b3f09
local     a_postgres-data

Expected behavior

Only one volume is created and data is persistent.

docker compose up
docker volume ls
DRIVER    VOLUME NAME
local     a_postgres-data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions