The problem of data persistence when Docker for windows builds Postgresql

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

mounting the folder generates the corresponding file after startup, but it will prompt that the permission problem is terminated. The sharing setting has 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.
Apr.09,2021

try adding-e PGD examples ATA=/tmp reference https://forums.docker.com/t/d.

or try executing docker volume create-- name gitlab-postgresql-d local and then docker compose to write

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

  volumes:
    gitlab-postgresql-volume:
      external: true

you are accustomed to using the compose, transfer command.
refer to https://forums.docker.com/t/t.

.
Menu