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?
Your discussion
This browser holds the management token for this post.
Save management token
Keep this private. Anyone with the token can resolve or delete this discussion.
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.