Mounting data volume for Postgres in docker for Windows doesn't work
Expected behavior
Postgres should start and mount the correct windows directory as a data volume
Actual behavior
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 ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
initdb: could not fsync file "/var/lib/postgresql/data/base/1": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/base/12406": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/base/12407": 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_clog": 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_xlog/archive_status": Invalid argument
initdb: could not fsync file "/var/lib/postgresql/data/pg_xlog": 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
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.
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
HINT: The server must be started by the user that owns the data directory.
pg_ctl: could not start server
Examine the log output.
stopped waiting
Information
docker-compose.yml file :
version: "2"
services:
slapd:
image: dcm4che/slapd-dcm4chee:2.4.40-8.1
ports:
- "389:389"
env_file: docker-compose.env
volumes:
- //c/Users/<user>/var/local/dcm4chee-arc/ldap:/var/lib/ldap
- //c/Users/<user>/var/local/dcm4chee-arc/slapd.d:/etc/ldap/slapd.d
postgres:
image: dcm4che/postgres-dcm4chee:9.6-8
ports:
- "5432:5432"
env_file: docker-compose.env
volumes:
- //c/Users/<user>/var/local/dcm4chee-arc/db:/var/lib/postgresql/data
dcm4chee-arc:
image: dcm4che/dcm4chee-arc-psql:5.8.1
ports:
- "8080:8080"
- "9990:9990"
- "11112:11112"
- "2575:2575"
env_file: docker-compose.env
environment:
WILDFLY_CHOWN: /opt/wildfly/standalone /storage
WILDFLY_WAIT_FOR: ldap:389 db:5432
AUTH_SERVER_URL: /auth
JAVA_OPTS: "-Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true"
links:
- slapd:ldap
- postgres:db
volumes:
- //c/Users/<user>/var/local/dcm4chee-arc/storage:/storage
- //c/Users/<user>/var/local/dcm4chee-arc/wildfly:/opt/wildfly/standalone
Note : Substituted <user> with my user
docker-compose.env file
LDAP_BASE_DN=dc=dcm4che,dc=org
LDAP_ORGANISATION=dcm4che.org
LDAP_ROOTPASS=secret
LDAP_CONFIGPASS=secret
ARCHIVE_DEVICE_NAME=dcm4chee-arc
AE_TITLE=DCM4CHEE
DICOM_HOST=localhost
DICOM_PORT=11112
HL7_PORT=2575
STORAGE_DIR=/storage/fs1
POSTGRES_DB=pacsdb
POSTGRES_USER=pacs
POSTGRES_PASSWORD=pacs
WILDFLY_ADMIN_USER=admin
WILDFLY_ADMIN_PASSWORD=admin
KEYCLOAK_ADMIN_USER=admin
KEYCLOAK_ADMIN_PASSWORD=admin
Steps to reproduce the behavior
- Share Drive using Docker for Windows->Settings->Shared Drive -> C:
- Use docker-compose up -d
Similar issue was already reported on https://github.com/docker/docker/issues/25908 but was redirected here to be checked/opened on https://github.com/docker/for-win/issues I have searched for this issue in Open and Closed issues list, but couldn't find any.
I'm using
- Windows 10 Pro, 64-bit
- Docker version 1.13.0, build 49bf474
I think this is a duplicate of https://github.com/docker/for-win/issues/39
For the time being, this won't work. You should either just use in-container storage or use a volume not mounted from your Windows host.
Is there a particular reason you want the data to be on the windows host?
Tried it with this approach: https://forums.docker.com/t/trying-to-get-postgres-to-work-on-persistent-windows-mount-two-issues/12456/5
command line
docker volume create --name postgres-data-volume -d local
docker-compose.yml
...
### PostgreSQL Container ####################################
postgres:
build: ./postgres
volumes:
- postgres-data-volume:/var/lib/postgresql/data
ports:
- "${POSTGRES_PORT}:5432"
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
networks:
- backend
### PostgreSQL PostGis Container ############################
postgres-postgis:
build: ./postgres-postgis
volumes:
- postgres-data-volume:/var/lib/postgresql/data
ports:
- "${POSTGRES_PORT}:5432"
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
networks:
- backend
...
### Volumes Setup #############################################
volumes:
mysql:
driver: "local"
...
postgres-data-volume:
external: true
also affected
Same here.
Ah come on, so you need a specific reason why to support a core Docker functionality? Like, well, I expect it to work with storing the data in a volume instead of being stuck in some random volume that I can't move to another server due to cryptic file paths and so I want my docker data + config to stay in the same folder so it's easy for me to backup, like a good DevOp would do? Holy Christ.
If MariaDB can do it, why Postgre can't? I don't want my data to be wiped out when I turn off the container.
+1 to this, it needs to be fixed.
Same issue, luckily I'm just picking my database now.
Same issue. Apparently no solutions for 1 year now...
Docker & Production ready.
That's two separate products.
Same problem.
I've solved the problem by creating a new volume like that :
docker volume create postgres_database
And then you link it like that :
services:
postgres:
restart: always
volumes:
- postgres_database:/var/lib/postgresql/data:Z
volumes:
postgres_database:
external: true
flavienbwk: Your solution works. :) Thank you.
Perfect!
This work but this is bad solution, global docker volumes creating inside of docker VM on Windows and MAC, what make pack of problems, such as no option to modify or inspect data of volumes.
- summ size of all volumes < size of virtual hard disc that used by docker, and no option to transperent volumes by physical devices
@Cugap Maybe a bad solution but there's no proposed solution by the Docker team, that has closed the issue whereas it is not solved. Maybe they should do something ?
Please consider reopening!
@friism pls reopen cause problem is still active, and maintaining of containerized DB is a real problem.
ping @carlfischer1
ping @gtardif
this is really frustrating. Please reopen this issue.
Local development with Docker Desktop for Windows as a single-node swarm is an important step to developing apps to deploy to Docker EE for us, as it allows us to create local overlays, networks and (almost) volumes and deploy stacks locally with 'docker stack deploy' + compose file. Being able to map a Windows folder to a volume (bind mount), with 'docker volume create' is quite important to replicate Docker EE functionality. Our development on Linux and macOS allows this, but many developers have Win10 laptops and this is a blocker.
Sure, we can create volumes and use them, but getting data into them for development is a bugger. We need to create a volume, then bring up a container that mounts it and then 'docker cp' our data into it or some other esoteric usage of rsync, etc. Aside from the inconvenience, it is inconsistent with how our macOS and Linux users work. PLEASE make this a priority.
Hi am running Linux containers using LCOW https://blogs.msdn.microsoft.com/premier_developer/2018/04/20/running-docker-windows-and-linux-containers-simultaneously/
when i try and run the official postgres container i get this issue, is it related or should i open another issue?
fixing permissions on existing directory /var/lib/postgresql/data ... initdb: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted