我在docker中通过run命令创建了postgres容器:
docker run --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 postgres:11.5-alpine
在pg-docker
容器中,/var/lib/postgresql/data拥有以下权限:
/ # 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
日志上写着The files belonging to this database system will be owned by user "postgres". This user must also own the server process.
现在,当我想在创建docker时使用挂载绑定时,我得到了:
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"
所以我决定忽略这个权限,将data
目录从容器发送到主机。我想我应该在dockerfile
中写commend .What是你的建议吗?我不知道如何实现忽略权限!
发布于 2019-09-02 22:41:17
我在linux上用这个命令工作,也许这是一个特定于Windows的问题?
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
https://stackoverflow.com/questions/57756372
复制相似问题