The following steps explain a workaround to connect from a container to a postgres server installed on the host system. This pattern can be applied to other (host) services as well.
- Install postgres
brew install postgres
brew services start postgres
(https://github.com/Homebrew/homebrew-services)
-
Attach a unused IP to the local lo0 interface
sudo ifconfig lo0 alias 10.200.10.1/24
-
Bind the postgres server to the new ip
vi /usr/local/var/postgres/postgresql.conf
- add
listen_addresses = '127.0.0.1,10.200.10.1'
- Trust the new ip
vi /usr/local/var/postgres/pg_hba.conf
- add
host all all 10.200.10.1/32 trust
docker run --rm -it -e POSTGRES_URL=postgres://[email protected]:5432/myDB ataube/myImage
More infos here: https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds