1

I created postgres container by run command in docker:

 docker run  --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 postgres:11.5-alpine   

In pg-docker container /var/lib/postgresql/data has this permissions:

/ # ls -la $PGDATA
total 128
drwx------   19 postgres postgres      4096 Sep  2 10:44 .
drwxr-xr-x    1 postgres postgres      4096 Aug 21 00:46 ..
-rw-------    1 postgres postgres         3 Sep  2 10:44 PG_VERSION
drwx------    5 postgres postgres      4096 Sep  2 10:44 base
drwx------    2 postgres postgres      4096 Sep  2 10:44 global
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_commit_ts
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_dynshmem
-rw-------    1 postgres postgres      4535 Sep  2 10:44 pg_hba.conf
-rw-------    1 postgres postgres      1636 Sep  2 10:44 pg_ident.conf
drwx------    4 postgres postgres      4096 Sep  2 10:44 pg_logical
drwx------    4 postgres postgres      4096 Sep  2 10:44 pg_multixact
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_notify
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_replslot
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_serial
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_snapshots
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_stat
drwx------    2 postgres postgres      4096 Sep  2 10:45 pg_stat_tmp
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_subtrans
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_tblspc
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_twophase
drwx------    3 postgres postgres      4096 Sep  2 10:44 pg_wal
drwx------    2 postgres postgres      4096 Sep  2 10:44 pg_xact
-rw-------    1 postgres postgres        88 Sep  2 10:44 postgresql.auto.conf
-rw-------    1 postgres postgres     23841 Sep  2 10:44 postgresql.conf
-rw-------    1 postgres postgres        24 Sep  2 10:44 postmaster.opts
-rw-------    1 postgres postgres        94 Sep  2 10:44 postmaster.pid
/ # echo $PGDATA
/var/lib/postgresql/data   

and it's log says The files belonging to this database system will be owned by user "postgres". This user must also own the server process.

Now when i want to use mount binding when created docker i got:

running bootstrap script ... 2019-08-31 13:34:38.428 UTC [47] FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
2019-08-31 13:34:38.428 UTC [47] HINT:  The server must be started by the user that owns the data directory.
child process exited with exit code 1
initdb: removing contents of data directory "/var/lib/postgresql/data"                      

So i decided to ignore this permissions to send out data directory from container to host. I think i should write commend in dockerfile.What is your suggestion ? I have no idea to implemented ignore permission!

11
  • With which command did you start the container when you say "mount binding"? Also, it is unclear for me if you used one postgres container where you want to connect to the database from the host machine, or if you are using two containers in this setup? You just want to run a postgres container with a volume for the data and be able to connect to the database from your host machine, did I get this right? Commented Sep 2, 2019 at 12:01
  • I am using windows docker so this is complete run command docker run --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 -v d:/datadir:/var/lib/postgresql/data postgres:11.5-alpine and i connected by pgadmin by 5433port @ElectRocnic Commented Sep 2, 2019 at 12:13
  • Yes, i just want to run a postgres container with a volume for the data and be able to connect to the database from my host machine but i got permission error has wrong ownership so i decided to ignore permission but how? @ElectRocnic Commented Sep 2, 2019 at 12:15
  • Well, I tried your command on my linux computer, made a test directory, inside this directory I made a new db_volume directory. Both, the test directory and the db_volumes directory are owned by the current user (not postgres) and inside test I ran docker run --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 -v db_volume:/var/lib/postgresql/data postgres:11.5-alpine. The output of postgres-startup was fixing permissions on existing directory /var/lib/postgresql/data ... ok. Maybe it is a Windows-specific issue where I cannot help. pgadmin worked. Commented Sep 2, 2019 at 12:32
  • db_volume is in your linux host? Where is the location exactly? i mean for example is in /home/user/test/db_volumes ? if true, no need add as you run docker run --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 -v /home/user/test/db_volumes:/var/lib/postgresql/data postgres:11.5-alpine ? @ElectRocnic Commented Sep 2, 2019 at 13:50

1 Answer 1

0

Worked for me on linux with this command, maybe it is a Windows-specific issue?

docker run --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 -v /full/path/to/db_volumes/on/host/machine:/var/lib/postgresql/data postgres:11.5-alpine

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.