Progrider

Programming discussion

Board index
Help✓ Resolved

container can't reach postgres on localhost

Two services in docker compose, web and db. Web fails with ECONNREFUSED 127.0.0.1:5432 even though db is up and the logs say it's accepting connections. Works fine when I run the app outside docker. What am I missing?

2 replies

Inside the web container, localhost is the web container. Use the service name: postgres://...@db:5432/. Check DATABASE_URL in your .env, it's probably still localhost from running outside docker.
Yep, .env still said localhost. Changed to db and it connected. Resolved.

Discussion resolved

This discussion is resolved. Its creator can reopen it to accept more replies.