简体   繁体   中英

Mount volume through boot2docker to the postgres container

I'm trying to run the container of postgres image with boot2docker on OSX.

This command works well on my Ubuntu:

docker run -v $(pwd)/data:/var/lib/postgresql/data postgres

but OSX says:

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"

chmod doesn't help.

I've tried option --user $(id -u):$(id -g) . It breaks container on Ubuntu, and it changes the error on OSX.

Ubuntu: chmod: changing ownership of '/var/lib/postgresql/data': Operation not permitted

OSX: chmod: changing permissions of '/run/postgresql': Operation not permitted

As it works for Ubuntu I want to run it on OSX, without creating my own images. But I have no idea how to deal with this error.

Any ideas?

I think this is a known boot2docker issue There's several workarounds but no solution there

#1) Overriding the /Users default share on boot2docker start:
boot2docker --vbox-share=$(pwd)/share-location=share-name up
#2) boot2docker ssh in and mount the custom share:
sudo mount -t vboxsf -o uid=999,gid=50 share-name [SHARE-FULL-PATH]/share-location

Mounting local folders into docker containers is not a good practice. It quite often results into problems with file permissions .

The better solution would be to change your setup using a volume container instead. There are also good concepts for volume container backups .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM