1

On my macbook I have postgres running in a docker container and I use a mapped volume to persist the data. This works perfectly locally.

However, when I try to do the same on an Ubuntu server the 'initial' data from the mapped volume is not working. Postgres starts up in an 'empty' initial state. I can see that the volume mapping is working and I've checked and confirmed the data folder for postgres within the container. Interestingly the mapping does seem to be working, since an added table and data in that table in the default postgres database IS persistent. Furthermore it is interesting to note that I'm getting an error when I try to create a table in a new database. The new database is persistent as well, but the table cant be saved as there is an error thrown:

could not open file "base/16384/2611": No such file or directory

This is expected as the folder base/16384 doesn't exist.

To me this seems this is a user/rights issue perhaps or some postgres setting? I tried running the container as root, which didn't help.

Any suggestions?

I'm starting the container with either docker-compose or from the command line using;

docker run --rm --name pg -e POSTGRES_PASSWORD=[password] -d -p 5432:5432 -v /root/docker/volumes/postgres:/var/lib/postgresql/data postgres -c listen_addresses='*'

EDIT: Did try a bunch of things;

  • The 'bazooka': I chmod 777 the mapped volume, to no effect
  • run docker container as user postgres:user (this seems to be the user:group of the mapped files), to no effect
  • run chown of PGDATA folder on docker container start to set owner to postgres:postgres as this seems to be the user:group that is creating a folder when I create a new database, to no effect. even still can't create a table eventhough the database folder was succesfully created

1 Answer 1

0

Instead of moving the actual data folder around I used pg_dump and pg_restore within the docker containers per suggestion on the docker forums. This did the trick

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.