PostgreSQL docker: "could not bind IPv6 socket: Cannot assign requested address"

After a long time, we finally figured out what was the problem -- adding explanation here, in case it helps others.

Since pgsql listens only to localhost by default, when it is running in the docker container, where we have the port mapping configuration, the external API was not able to connect to the pgsql server.

The solution is to allow pgsql to listen to all IP addresses:

  1. Connect to db container shell: $ docker exec -ti db bash

  2. Change the configuration file /var/lib/postgresql/data/postgresql.conf to allow pgsql to listen to all IPs: listen_addresses = '*'


Certain edits have to be made to the postgres.conf and pg_hba.conf files in order for Postgres inside the container to listen to connections from the host:

See the Gotchas section at the cityseer/postgis repo.

  • Check that your postgresql.conf file has the listen_addresses item uncommented and set to listen to all ports, i.e. listen_addresses = '*';
  • Check that your pg_hba.conf file allows the docker container's Postgres to provide local and host access per the following two lines:

    local all all trust

    host all all 0.0.0.0/0 trust