piolad / chat-app

3 stars 1 forks source link

How can we save data in databases between diffrent images #22

Open jakublaz opened 5 months ago

jakublaz commented 5 months ago

now when we close the app and delete all iamges or start a new one from new images the data is not saved so we can not store progress made or any data inserted

piolad commented 4 months ago

Bind mounts

One idea is to use bind mounts - copying a folder from container filesysten onto host filesystem

e.g for postgres it could be something like this:

    volumes:
      - type: bind
        source: ./pg-save/
        target: /var/lib/postgresql/data

Each database container will have a different target value which you can probably find on the internet

This soulution should work fine for preserving data on our own system. However, I do not think we should commit the database data and push it onto git This could cause many problems e.g. if we decide to change the way we push things onto the database instead.

Named volume

Are not accessible from host filesystem (kept somewhere in Docker)

    volumes:
      - pgdata:/var/lib/postgresql/data