I've had a docker swarm setup running for months now but started receiving the following error today:
FATAL: no pg_hba.conf entry for host "10.0.7.2", user "xxxx", database "xxxx", SSL off
This is how my docker-compose.yml looked like initially:
version: '3.6'
services:
web:
image: myimage
networks:
- frontend
- backend
depends_on:
- db
deploy:
replicas: 3
environment:
DEBUG: '0'
DATABASE_URL: 'postgres://xxxx@xxxx:5432/xxxx'
command: uwsgi --ini etc/uwsgi.ini --http-socket 0.0.0.0:8001
logging:
driver: "json-file"
options:
max-size: "10M"
max-file: "20"
db:
image: postgres:9.6.9
networks:
- backend
ports:
- "5432:5432"
volumes:
- ./data/postgres:/var/lib/postgresql/data
deploy:
placement:
constraints: [node.role == manager]
logging:
driver: "json-file"
options:
max-size: "10M"
max-file: "20"
networks:
frontend:
backend:
driver: overlay
attachable: true
After reading how I could potentially solve this I also added this to the db's volume:
- ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf
with a modified pg_hba.conf where I added the following for testing purposes:
host all all 0.0.0.0/0 trust
Afterwords I removed the stack and deployed it again. I've checked the db container and pg_hba.conf reflected the changes but the issues was still there.
Figured it out, had to comment out: host all postgres 0.0.0.0/0 reject from the pg_hba.conf as well along with adding host all all 0.0.0.0/0 trust.
Better if I use a custom username + only allow a specific ip range.
Ran across this just now. Another approach if you don't care so much about configuring your postgres DB (or the database itself) it just to delete the mapped volume and let it be re-created
Can someone explain me this solution in more detail ?
Use
command: postgres -c listen_addresses='*'
and remove volumes wiht down -v and then it will work for all IPs. May be there is a way to remove volume of the pg only, but I don't know it.
Most helpful comment
Ran across this just now. Another approach if you don't care so much about configuring your postgres DB (or the database itself) it just to delete the mapped volume and let it be re-created