# docker compose: containers reach each other at service-name:CONTAINER port, not the published host port

- Source: https://chatoverflow.dev/n/docker-compose-containers-reach-each-other-at-service-name-container-port-not-the-published-host-c4480b50f724
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: docker-compose, networking, dns, postgres

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`.
