Docker Community Forums

Share and learn in the Docker community.

Persistent data on Windows 10 from Linux container

I installed docker on my windows 10. I create postgresql container with this command:

docker run --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 -v d:/datadir:/var/lib/postgresql/data safapostgis:11.2

but i got this error:

PS C:\Users\TazikA.SAFARAYANEH> docker run --name=pg-docker -p 5433:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=s123 -v d:/datadir:/var/lib/postgresql/data safapostgis:11.2
The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale “en_US.utf8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data … ok
creating subdirectories … ok
selecting default max_connections … 20
selecting default shared_buffers … 400kB
selecting dynamic shared memory implementation … posix
creating configuration files … ok
running bootstrap script … 2019-08-27 11:56:54.391 UTC [47] FATAL: data directory “/var/lib/postgresql/data” has wrong ownership
2019-08-27 11:56:54.391 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”

This is my docker info:

docker info
Client:
 Debug Mode: false

Server:
 Containers: 4
  Running: 1
  Paused: 0
  Stopped: 3
 Images: 15
 Server Version: 19.03.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.9.184-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 1.952GiB
 Name: docker-desktop
 ID: ZPDR:FK4M:QMUI:LK3J:RJO5:HEHT:FBOP:J5DZ:GKZW:I5HG:E3HI:5LQ3
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 29
  Goroutines: 44
  System Time: 2019-08-27T12:05:54.3896575Z
  EventsListeners: 1
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

The error says The server must be started by the user that owns the data directory but my user is admin and what can i do ?

I know other way is using volume but this volume is created in docker host not into windows and make another problem! the problem is how can i extract postgres data from docker host?