Hey, I have a problem connecting my local database to n8n, I have a docker running on port 5432.
When I set host to localhost or 127.1.0.0 it throws the error connection refused and when I try to connect through bridge IP address it is just loading and not doing anything until I manually close it. Thank you in advance
The error is due to a common confusion when using Docker:
When n8n is in a separate container, localhost refers to the n8n container, not the host.
Therefore:
localhost or 127.0.0.1 will not work from within a separate n8n container.
Port 5432 is exposed to the host, but not necessarily to other containers via localhost.
You should use the service name as the host
Host: postgres
instead of localhost or IP.
Why does it work?
Docker automatically generates an internal DNS network where services can be discovered by name (the name postgres comes from docker-compose.yml).