鍍金池/ 問答/Linux  數(shù)據(jù)庫/ Docker for windows 搭建 Postgresql 時(shí)數(shù)據(jù)持久化問

Docker for windows 搭建 Postgresql 時(shí)數(shù)據(jù)持久化問題

操作系統(tǒng):Windows10
工具:Docker for windows
數(shù)據(jù)庫:Postgresql 11

docker run --name pg -d -e POSTGRES_PASSWORD=123 -v e:/docker_data/pg:/var/lib/postgresql/data -p 5432:5432 postgres

啟動(dòng)后掛載文件夾生成了相應(yīng)的文件,但會(huì)提示權(quán)限問題終止,之前已經(jīng)做了共享設(shè)置。

共享設(shè)置

掛載文件夾

2018-08-14 03:19:29.050 UTC [1] FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
2018-08-14 03:19:29.050 UTC [1] HINT:  The server must be started by the user that owns the data directory.
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... initdb: could not fsync file "/var/lib/postgresql/data/base/1": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/base/12993": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/base/12994": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/base": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/global": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_commit_ts": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_dynshmem": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_logical/mappings": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_logical/snapshots": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_logical": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact/members": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact/offsets": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_notify": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_replslot": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_serial": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_snapshots": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_stat": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_stat_tmp": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_subtrans": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_tblspc": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_twophase": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_wal/archive_status": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_wal": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_xact": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_tblspc": Invalid argument
ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
    pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2018-08-14 03:20:27.013 UTC [39] FATAL:  data directory "/var/lib/postgresql/data" has wrong ownership
2018-08-14 03:20:27.013 UTC [39] HINT:  The server must be started by the user that owns the data directory.
 stopped waiting
pg_ctl: could not start server
Examine the log output.
回答
編輯回答
尛憇藌

試試加上-e PGD??ATA=/tmp 參考https://forums.docker.com/t/d...

或者試試執(zhí)行docker volume create --name gitlab-postgresql -d local 然后docker compose這么寫

services:
  postgresql:
    restart: always
    image: sameersbn/postgresql:9.5-1
    volumes:
      - gitlab-postgresql-volume:/var/lib/postgresql:Z

  volumes:
    gitlab-postgresql-volume:
      external: true

用慣了compose, 轉(zhuǎn)命令這個(gè)你自己轉(zhuǎn)吧
參考https://forums.docker.com/t/t...

2017年11月11日 01:57