Search code examples
databasepostgresqldockerdocker-composedocker-volume

Docker volumes gets overwritten with docker compose v2


I have a few dockers that i run for a discord bot. One of them is my postgres database. I'm not working on the server that hosts the bot and everything.

On my computer I'm using old docker compose : docker-compose (v1.29.2) and the server is using the new one docker compose (v2.21.0). When i down the dockers and i up them again (with or without --build) the old database volume is kept and my data is safe. But when i down them and up them on the server, each time, the data is erased as if i created a new volume.

Weirdly, it also happens with the database volume (SQLite here) of our WikiJS instance which is also dockerized on the same server.

Here is my database service in the docker-compose.yml file :

  db:
    image: postgres:latest
    volumes:
      - ./initialization-scripts:/docker-entrypoint-initdb.d/

I checked the docs and the release notes and found nothing interesting.

Do you have any idea of how to turn this overwrites off ? Thanks for everything !


Solution

  • As pointed by @BMitch, my issue here was that i didn't had a volume for my data. I don't know why it changed from v1 to v2.

    To fix my issue i added a bind volume to the data folder :

      db:
        volumes:
          - ./initialization-scripts:/docker-entrypoint-initdb.d/
          - ./pg_data:/var/lib/postgresql/data