Linux : Docker configuration - accessing PostgreSQL server on the host

This page last changed on May 01, 2015 by admin.


Docker version 1.5.0

Get docker container info

docker inspect <container-name>

Docker delivers a huge chunk of config. For us now the relevant part is the networking:

 "NetworkSettings": {
        "Bridge": "docker0",
        "Gateway": "",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "IPAddress": "",
        "IPPrefixLen": 16,
        "IPv6Gateway": "",
        "LinkLocalIPv6Address": "fe80::42:acff:fe11:7",
        "LinkLocalIPv6PrefixLen": 64,
        "MacAddress": "02:42:ac:11:00:07",
        "PortMapping": null,
        "Ports": {
            "8080/tcp": [
                    "HostIp": "",
                    "HostPort": "8091"

Access PostgreSQL server on host from container

Listen to all IP addresses - in postgresql.conf:

listen_addresses = '*'

Allow connections from docker container - in pg_hba.conf add

host   all    all   trust

Make docker play nice with ufw, in /etc/default/ufw adjust the forward policy (see


And open up a port for the docker container and allow the bridge:

sudo ufw allow from to any port 5432
sudo ufw allow in on docker0