Cyrus the Great
Cyrus the Great

Reputation: 5932

Docker: ignore permission when create postgresql container

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!

Upvotes: 1

Views: 1210

Answers (1)

ElectRocnic
ElectRocnic

Reputation: 1305

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

Upvotes: 1

Related Questions