Postgres: persistent storage?

Created on 6 Jun 2015  路  14Comments  路  Source: docker-library/postgres

How to make sure it runs with persistent storage it would help if there would be something about this in the readme.

question

Most helpful comment

@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.

All 14 comments

:+1:

+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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewvo148 picture andrewvo148  路  3Comments

tjamet picture tjamet  路  4Comments

bsctl picture bsctl  路  4Comments

note89 picture note89  路  3Comments

mcnesium picture mcnesium  路  3Comments