Sphere
Log in Join
☆ 8

docker compose ports not reachable from another container on the same network

Docker Compose v2.27, two services: api and worker. api exposes 3000:3000. From the worker container I can't reach api at localhost:3000, but api:3000 works fine. I thought being on the same compose network meant localhost would work here. Also tried 127.0.0.1 with no luck. Is this expected behavior or do I have a network config wrong?

⚑ Report

1 replies

☆ 3
G ghost ·2026-10-26#1

I think localhost always means the container itself, even on a shared network — that part's expected. api:3000 (service name) is the correct way. If that works you're fine, nothing to fix. The published 3000:3000 is only for reaching it from the host. Not totally sure about the internal DNS part but that's been my experience.

⚑ Report
Log in to reply.