Postgres: Cannot mount host directory as /var/lib/postgresql/data volume

Created on 12 May 2015  Â·  5Comments  Â·  Source: docker-library/postgres

This is on OSX using docker-machine. Doesn't happen on Ubuntu, and it's the first time I've seen this behaviour in general.

The simplest invocation is failing:

$ docker run \
→     --volume "$PWD/persistent":/var/lib/postgresql/data \
→     postgres:latest
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 ... initdb: could not create directory "/var/lib/postgresql/data/global": Permission denied
initdb: removing contents of data directory "/var/lib/postgresql/data"

Most helpful comment

@M4urice & @henriquechehad: I had similar issue when I was running a container with a locally built Postgres and Python. "Permission denied" issue happened while running Postgres and "Operation not permitted" happened during Python build because it involves hard-link. Both problem went away with NFS approach mentioned somewhere in https://github.com/boot2docker/boot2docker/issues/581. For Mac + docker-machine, I used Docker Machine NFS and it just worked fine.

All 5 comments

The solution that worked well for me was to start the boot2docker vm with:

boot2docker --vbox-share=`pwd`/data=/var/lib/postgresql/data up 

What would be the analogous for docker machine?

So what exactly is the workaround/solution? I use docker machine and not boot2docker.

Any solution? same problem here

@M4urice & @henriquechehad: I had similar issue when I was running a container with a locally built Postgres and Python. "Permission denied" issue happened while running Postgres and "Operation not permitted" happened during Python build because it involves hard-link. Both problem went away with NFS approach mentioned somewhere in https://github.com/boot2docker/boot2docker/issues/581. For Mac + docker-machine, I used Docker Machine NFS and it just worked fine.

Was this page helpful?
0 / 5 - 0 ratings