1

I have a postgres docker cluster running in a docker swarm environment with an overlay network. everything looks fine until when I try accessing the created container from a remote host with this command psql -h -p -U .

I'm setting up the postgres initialization parameters using an environment variable file that looks like this

`# the name of the cluster
PATRONI_SCOPE=pg-test-cluster

# create an admin user on pg init
PATRONI_admin_OPTIONS=createdb, createrole
PATRONI_admin_PASSWORD=admin

# host and port of etcd service
PATRONI_ETCD_HOST=etcd:2379

# location of password file
PATRONI_POSTGRESQL_PGPASS=home/postgres/.pgpass

# address patroni will use to connect to local server
PATRONI_POSTGRESQL_LISTEN=0.0.0.0:5432

# replication user and password
PATRONI_REPLICATION_PASSWORD=abcd
PATRONI_REPLICATION_USERNAME=replicator

# address patroni used to receive incoming api calls
PATRONI_RESTAPI_LISTEN=0.0.0.0:8008

# api basic auth
PATRONI_RESTAPI_PASSWORD=admin
PATRONI_RESTAPI_USERNAME=admin

# patroni needs superuser adminstrate postgres
PATRONI_SUPERUSER_PASSWORD=postgres
PATRONI_SUPERUSER_USERNAME=postgres`

The error I get is

`psql: could not connect to server: Connection refused
    Is the server running on host "10.66.112.29" and accepting
    TCP/IP connections on port 5000?`

Im exposing port 5000 through patroni rest api for master DB.

Any ideas where I'm missing the point? thanks !

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
polycarp royal
  • 95
  • 1
  • 2
  • 10
  • 1
    What is the IP you are trying to connect to? Is that the server where your docker is running? And can you share the initialization command/composer file for how you set it the container up? – Sven Hakvoort Nov 29 '18 at 12:15
  • yes the server is the same docker daemon is running. The port I'm exposing is 5000 for the postgres container, I do this using haproxy load balancer then I have a .yml file that I build a docker stack with to start the services. This is the bit that exposes the ports from the .yml file services: haproxy: image: haproxy:alpine ports: - "5000:5000" - "5001:5001" - "8008:8008" . Port 5001 is for replication and 8008 is used by patroni api for frontend traffic routing. – polycarp royal Nov 29 '18 at 15:21
  • Could you share the whole yml and/or other configurations for docker? I suspect the containers have not been linked properly – Sven Hakvoort Nov 30 '18 at 06:35
  • kindly use this github link. I use that repo to set up my environment. https://github.com/seocahill/ha-postgres-docker-stack – polycarp royal Dec 06 '18 at 14:13
  • Could you try adding a `ports` config to your db containers? Do this like `ports: - 5000` this will only publish that port within the network. Allowing haproxy to access this container. – Sven Hakvoort Dec 06 '18 at 14:29
  • when I build the docker stack that uses patroni rest api(which exposes port 5000 and 5001 for all db services to the haproxy load balancer), this is then how I access the DB containers remotely psql -h -p 5000 -d database. Is this close to your suggestion? – polycarp royal Dec 10 '18 at 09:25

0 Answers0