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 a few things to solve this, all didn’t work:
- The ‘bazooka’: I chmod 777 the mapped volume, to no effect
- Run docker container as root, 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 even though the database folder was successfully created
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='*'
Or the docker-compose.yaml:
version: '3' services: redis: image: redis restart: always volumes: - redis:/data pg-nex: image: postgres user: postgres:postgres restart: always environment: POSTGRES_PASSWORD: docker POSTGRES_USER: postgres command: postgres -c listen_addresses='*' ports: - 5431:5432 volumes: - $HOME/docker/volumes/postgres:/var/lib/postgresql/data superset: image: amancevice/superset restart: always depends_on: - pg-nex - redis environment: MAPBOX_API_KEY: ports: - "8091:8088" volumes: - /root/docker/volumes/superset:/etc/superset volumes: pg-nex: redis: