Docker / Postgres: Mounting an existing database within a dockerized Postgresql
So I’m having a problem mounting an existing set of data for Docker Postgres that I cannot figure out for the life of me. Here’s my docker compose file.
version: '2' services: postgresql: image: postgres:9.5 environment: - PGDATA=/data ports: - '5432:5432' volumes: - ~/.postgresql:/data web: build: . command: sbt/sbt run volumes: - .:/app ports: - '9001:9001' depends_on: - postgresql
Here’s the error I see
ostgresql_1 | FATAL: data directory "/data" has wrong ownership postgresql_1 | HINT: The server must be started by the user that owns the data directory.
Does anyone have any clue how to fix it? Thank you
PS I am using Docker Machine through OSX if that makes a difference in this problem.
One Solution collect form web for “Docker / Postgres: Mounting an existing database within a dockerized Postgresql”
The error message is pretty clear. I think the container runs postgres with user
postgres which has a uid/gid of
999 (see https://github.com/docker-library/postgres/blob/3f8e9784438c8fe54f831c301a45f4d55f6fa453/9.5/Dockerfile line 5). You need to
chown your host data folder to a user with the same