Hi everyone,
Same issue as https://stackoverflow.com/questions/41637505/how-to-persist-data-in-a-dockerized-postgres-database-using-volumes
When I mount my data volume, it remains empty in my host. Using /var/lib/postgresql/data instead /var/lib/postgresql does not helps. Giving 755 permission on whole data directory finally share files, but why and how to make it working with default access ?
docker-compose version 1.17.0, build ac53b73
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
Client:
Version: 18.03.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:10:01 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:08:31 2018
OS/Arch: linux/amd64
Experimental: false
services:
test_postgres:
container_name: test_postgres
environment:
POSTGRES_DB: weeha
POSTGRES_PASSWORD: weehe
POSTGRES_USER: wooho
image: postgres:10.4
restart: always
volumes:
- ./data:/var/lib/postgresql/data:rw
version: '2.0'
docker-compose up -dls -la ./datadocker exec -ti test_postgres ls -la /var/lib/postgresql/data./data is empty
/var/lib/postgresql/data is not empty
./data and /var/lib/postgresql/data should have the same contents
Ubuntu 16.x
version: "2"
services:
test_postgres:
container_name: test_postgres
environment:
POSTGRES_DB: weeha
POSTGRES_PASSWORD: weehe
POSTGRES_USER: wooho
image: postgres:10.4
restart: always
volumes:
- ./data:/var/lib/postgresql/data:rw
# ls
docker-compose.yml
# docker-compose up -d
WARNING: The Docker Engine you're using is running in swarm mode.
Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.
To deploy your application across the swarm, use `docker stack deploy`.
Creating network "postgres-476_default" with the default driver
Creating test_postgres ... done
# ls
data/ docker-compose.yml
# sudo ls data
base pg_logical pg_stat pg_wal
global pg_multixact pg_stat_tmp pg_xact
pg_commit_ts pg_notify pg_subtrans postgresql.auto.conf
pg_dynshmem pg_replslot pg_tblspc postgresql.conf
pg_hba.conf pg_serial pg_twophase postmaster.opts
pg_ident.conf pg_snapshots PG_VERSION postmaster.pid
I'm not able to reproduce
Given that we can't reproduce, I'm afraid to say this is likely something environmental (not an issue in the image itself which we could fix).
For further help troubleshooting, I'd recommend trying the Docker Community Forums, the Docker Community Slack, or Stack Overflow.
Hi @weeger were you able to resolve this issue?
i had the same problem. These steps helped me:
1) mount data folder as wglambert wrote.
2) add postgres user into the host with the same id group and user, otherwise postgres have no permissions to write files on your host
Most helpful comment
I'm not able to reproduce