Persist Postgres data in my host so data won’t be deleted every time I run a container.
Actual behavior
db_1 | FATAL: data directory “/var/lib/postgresql/data/pgdata” has wrong ownership
db_1 | HINT: The server must be started by the user that owns the data directory.
Information
Not sure if it will have any valuable info, but a diagnostic was uploaded with id: BD1854A3-041C-4C22-9FE5-1E5045910B45/2016-07-13_07-36-45
I am also experiencing this issue when attempting to run Postgres within a Docker container. I did a bit of digging and it appears that the Docker for Windows client (1.12.0-rc4-beta19) is mounting the volumes using CIFS and is passing a slew of options:
Of particular interest are uid, gid, noforceuid, noforcegid, and nounix. I haven’t poked around at this yet but it seems as if we are getting stuck with uid=0,gid=0 which corresponds to root:root (as @greut pointed out).
In my experience mapping uid/gid between Windows and Linux can be pretty painful due to differences between the POSIX and NTFS ACL schemes. One potential solution could be more granular management of shares and mount options. I would be very interested to hear others’ opinions on this issue and any potential solutions.
But how do I create a data volume mapped to a local volume on Docker Compose? I need to persist the database server info so I don’t lose the information each time I run the container.
Yep same issue here. I’ve tried doing it in my User directory on my C: drive instead but ends up with:
db_1 | syncing data to disk ... initdb: could not fsync file "/var/lib/postgresql/data/base/1": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/base/12374": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/base/12379": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/base": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/global": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_clog": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_commit_ts": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_dynshmem": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_logical/mappings": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_logical/snapshots": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_logical": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact/members": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact/offsets": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_multixact": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_notify": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_replslot": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_serial": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_snapshots": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_stat": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_stat_tmp": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_subtrans": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_tblspc": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_twophase": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_xlog/archive_status": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_xlog": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data": Invalid argument
db_1 | initdb: could not fsync file "/var/lib/postgresql/data/pg_tblspc": Invalid argument
Then
db_1 | waiting for server to start....FATAL: data directory "/var/lib/postgresql/data" has wrong ownership
db_1 | HINT: The server must be started by the user that owns the data directory.
It does seem to create files and folders but just won’t start based on permissions