Hello
I'm using postgres 9.4 image and I wish to have my data persisted under /data/2life/db. In compose, I have such a definition where i bind /data/2life/db to /var/lib/postgresql
db:
image: postgres:9.4
environment:
- POSTGRES_USER=rr
- PGPASSWORD=rr
- POSTGRES_PASSWORD=rr
volumes:
- /data/2life/db:/var/lib/postgresql
however when I inspect my container I notice that the data is persisted in an other volume /var/lib/docker/volumes... which i didn't asked.
"Volumes": {
"/var/lib/postgresql": "/data/2life/db",
"/var/lib/postgresql/data": "/var/lib/docker/volumes/c90e06963f716494b5d3a3c24a61796dcaee983697ad65c3d76fe069f45d17b1/_data"
},
does someone has an explanation or another way to persist data where we want ?
thx
The VOLUME is declared as /var/lib/postgresql/data, so you would need to asjust your bind mount to be that directory.
I think we need better documentation on what to mount to persist data to your host; like mysql
but if i bind to /var/lib/postgresql/data then it's empty and there is the following error:
db_1 | postgres cannot access the server configuration file "/var/lib/postgresql/data/postgresql.conf": No such file or directory
Postgres will create that file on first start with postgres initdb, so it should only be empty if the postgres user in the container is unable to write to the directory which only happens if root in the container was unable to chown it. Maybe docker info, docker version, uname -a, and docker logs on the container?
you're right it is about write rights. (what a sentence to pronounce!)
I wasn't able to use another user as POSTGRES_USER=postgres but once i used postgres it worked.
thanks for you help
Could anyone give me an example? Thanks
@vallettea - I just bumped into this exact issue. Could you please provide a solution example? I know there is a way to solve this from reading the comments in this issue. But I don't know how.
I'd recommend trying a dedicated support forum such as the Docker Community Forums, the Docker Community Slack, or Stack Overflow.
Most helpful comment
Could anyone give me an example? Thanks