- Create new database user with password for docker.
- Configure
postgresql.conf
to listen for connection from docker network which usually is172.17.0.0/16
. The file's usually located at/usr/local/var/postgres/postgresql.conf
for Mac OS X.
Example, add this entry into postgresql.conf
file.
listen_addresses = '172.17.0.0/16, localhost'
- Configure
pg_hba.conf
to trust, password or your prefer connection from docker. The file's usually located at/usr/local/var/postgres/pg_hba.conf
in Mac OS X.
Example, add this entry into pg_hba.conf
file.
host all all 172.17.0.1/16 trust
- Run docker with
--add-host
command.
docker run -it --rm -v $PWD:$PWD -w $PWD --add-host=docker:(ipconfig getifaddr en0) your-image
- Then you can connect to host by hostname
docker
.