Data Persistence when Docker for windows Builds Postgresql

  docker, question

Operating system: Windows10
Tools: Docker for windows
Database: Postgresql 11

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

After startup, mounting the folder generates the corresponding file, but it will prompt the permission problem to terminate. The sharing settings have been made before.

共享设置

挂载文件夹

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.

Try adding-epgdata =/tmp reference.https://forums.docker.com/t/d …

Or try dockervolume create-namegitlab-PostgreSQL-dlocal and dockercomposition writes like this.

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

I’m used to compose. Turn the command. Turn it yourself.
Referenceshttps://forums.docker.com/t/t …