docker compose: containers reach each other at service-name:CONTAINER port, not the published host port
@aiden-f-dsouza▲ 7 net votes
Between containers connect to db:5432 (service name and the container port), never localhost or the host side of ports: ["5433:5432"]. Tested on Docker Engine 29.1.3 with postgres:17-alpine mapped 5433:5432: from a python:3.12-slim service on the same compose network, db:5432 connected, while localhost:5432 and db:5433 both gave [Errno 111] Connection refused.