How to make sure it runs with persistent storage it would help if there would be something about this in the readme.
:+1:
+1! This would need to be a PR to
https://github.com/docker-library/docs/blob/9a3c64afc13ef2949b626dc7750b98158b14eef0/postgres/content.md,
probably adding content very similar to what's in mysql:
https://github.com/docker-library/docs/blob/9a3c64afc13ef2949b626dc7750b98158b14eef0/mysql/content.md#where-to-store-data
+1
I added an example on how I did this here:
https://github.com/DanielCaldwell/postgres-docker-persistant-data
Maybe it can help someone else.
Using docker compose, I can't get the volume sharing working properly. Mounting /var/lib/postgresql from the container to the host only exposes data dir without the contents in that dir. If I docker exec the container, the content is fine. Anyone has the same problem?
@akbargumbira, it needs to be mounted to /var/lib/postgresql/data, otherwise the docker volume defined there will be mounted on that directory and thus not show up in your bind mount.
@yosifkit thanks!
@yosifkit btw, I thought it would be recursively mounted? https://github.com/docker/docker/issues/3782
On other official db containers like redis, nothing needs to be done to make data persistence work by default. Ideally I can start and stop containers based on this image and have data persists without me having to add -v in docker run or a custom VOLUMES entry in a Dockerfile.
@iMerica Have you found otherwise with this image? It already has VOLUME /var/lib/postgresql/data. I've started and stopped containers based on this image many times and they always come back up with the same data.
This issue seems to be talking about persistence that survives destroying the container. The situation here is the same as every other container with a VOLUME statement for its data directory, including redis.
Hmm. Yes, data is lost on restarts鈥揳nd it's happening for everyone in my office. Thanks for your reply, it could be due to the initialization script. I'll open a bug if the issue persists.
Thanks @yosifkit! I just needed to add -v /var/lib/postgresql/data:/var/lib/postgresql/data
shouldn't -v /var/lib/postgresql:/var/lib/postgresqlwork as well?
@vytautasgimbutas, nope :cry:, there is a VOLUME declared on /var/lib/postgresql/data, so docker will create that as a separate mount within your bind-mounted directory and you would end up with just an empty data folder.
Since this issue seems unrelated to any errors in the image itself, and being two years without further comment, I'm going to prune the issue.
If you believe this to be in error then let me know and I'll re-open it
Given that the issue is more of a usability question, it would be more suited for the Docker Community Forums, the Docker Community Slack, or Stack Overflow.
Most helpful comment
@vytautasgimbutas, nope :cry:, there is a
VOLUMEdeclared on/var/lib/postgresql/data, so docker will create that as a separate mount within your bind-mounted directory and you would end up with just an emptydatafolder.