Skip to content

Instantly share code, notes, and snippets.

@raghothams
Last active January 25, 2018 18:20
Show Gist options
  • Save raghothams/98f6c8277e1a3c1ab3c1d18e6d32da63 to your computer and use it in GitHub Desktop.
Save raghothams/98f6c8277e1a3c1ab3c1d18e6d32da63 to your computer and use it in GitHub Desktop.
docker connect host db to container

Connect to host db from docker container

  1. modify /etc/postgresql/9.5/main/postgresql.conf

add listen_addresses = '*'

  1. modify /etc/postgresql/9.5/main/pg_hba.conf

add host all all 0.0.0.0/0 trust

  1. restart postgresql

  2. Add --add-host to docker run command

docker run --add-host database:172.17.0.1 <container>

This will add an entry in /etc/hosts of container with

172.17.0.1 database

  1. connect to postgres from docker container user database as host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment