for-win icon indicating copy to clipboard operation
for-win copied to clipboard

Mounting data volume for Postgres in docker for Windows doesn't work

Open vrindanayak opened this issue 9 years ago • 94 comments

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

  1. Share Drive using Docker for Windows->Settings->Shared Drive -> C:
  2. 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

vrindanayak avatar Jan 30 '17 14:01 vrindanayak

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?

friism avatar Jan 30 '17 16:01 friism

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

colonelz avatar Jul 19 '17 10:07 colonelz

also affected

redfellow avatar May 18 '18 11:05 redfellow

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.

darkguy2008 avatar Jun 11 '18 06:06 darkguy2008

Same issue, luckily I'm just picking my database now.

MatthewLymer avatar Jun 19 '18 20:06 MatthewLymer

Same issue. Apparently no solutions for 1 year now...

flavienbwk avatar Jul 11 '18 17:07 flavienbwk

Docker & Production ready.

That's two separate products.

redfellow avatar Jul 11 '18 17:07 redfellow

Same problem.

Greifenkralle avatar Jul 16 '18 08:07 Greifenkralle

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 avatar Jul 16 '18 09:07 flavienbwk

flavienbwk: Your solution works. :) Thank you.

Greifenkralle avatar Jul 16 '18 10:07 Greifenkralle

Perfect!

flavienbwk avatar Jul 16 '18 10:07 flavienbwk

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 avatar Sep 25 '18 14:09 Cugap

@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 ?

flavienbwk avatar Sep 29 '18 14:09 flavienbwk

Please consider reopening!

marcospgp avatar Sep 30 '18 21:09 marcospgp

@friism pls reopen cause problem is still active, and maintaining of containerized DB is a real problem.

Cugap avatar Oct 01 '18 07:10 Cugap

ping @carlfischer1

friism avatar Oct 06 '18 17:10 friism

ping @gtardif

carlfischer1 avatar Oct 09 '18 15:10 carlfischer1

this is really frustrating. Please reopen this issue.

beeplin avatar Oct 12 '18 12:10 beeplin

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.

getsomebread avatar Nov 01 '18 15:11 getsomebread

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

ta32 avatar Nov 06 '18 06:11 ta32