Running a postgres container with data volumes through a docker machine

I have a problem running the postgres container with setting volumes for the data folder on my Mac OS machine. I tried to run it like this:

docker run \ --name my-postgres \ -e POSTGRES_USER=admin \ -e POSTGRES_PASSWORD=password \ -e POSTGRES_DB=some_db_dev \ -v $PG_LOCAL_DATA:/var/lib/postgresql/data \ -d postgres:9.5.1 

Every time I got the following output in the logs:

 * Starting PostgreSQL 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 enabled. fixing permissions on existing directory /var/lib/postgresql/data ... ok initdb: could not create directory "/var/lib/postgresql/data/pg_xlog": Permission denied initdb: removing contents of data directory "/var/lib/postgresql/data" 

Versions of dockers, docker machines, virtual boxes and boot2docker:

 docker-machine version 0.6.0, build e27fb87 Docker version 1.10.2, build c3959b1 VirtualBox Version 5.0.16 r105871 boot2docker 1.10.3 

I have seen many publications on this topic, but most of them are out of date. I tried to make a similar solution, as for mysql , but that did not help.

Can someone please update me: is there any solution for running a postgres container with data volumes through a docker machine?

Thanks!

+6
source share
1 answer

If you are using a Mac dock, you cannot currently connect to a directory that is not part of your local user space ( /Users/<user>/ ) without additional configuration.

This is because on Mac, Docker automatically sets the binding binding to the ~ home directory. Remember that since Docker is hosted on a virtual machine that is not your local Mac OS, all volumes are mounted relative to the host virtual machine, not your machine. This means that by default, Docker cannot see your Mac directories because it is hosted on a separate virtual machine from your Mac OS.

 Mac OS => Linux Virtual Machine => Docker ^------------------^ Docker Can See VM ^-----------------X----------------^ Docker Can't See Here 

If you open VirtualBox, you can create other mounts (i.e. shared folders) on your local computer to the host virtual machine, and then access them that way.

See this issue for a specific topic: https://github.com/docker/machine/issues/1826

I believe that the Docker team will add these features to the upcoming releases (especially since the native Mac version works shortly).

+2
source

All Articles