When you containerize a pipeline, the most common failure isn’t your code — it’s usually how services address each other.

The rule

Inside a container, localhost means that container, not your laptop and not another container.

In Docker Compose: use service names

If Postgres is started as a Compose service (for example pgdatabase), other containers in the same Compose project should connect using the service name:

  • Host: pgdatabase
  • Port: 5432

Example connection string:

postgresql://root:root@pgdatabase:5432/ny_taxi

From your laptop (host)

From your host OS, you connect via the published port:

  • Host: localhost
  • Port: 5432

Example:

pgcli -h localhost -p 5432 -U root -d ny_taxi

Notes

  • Docker Desktop (Mac/Windows): host.docker.internal is commonly used for reaching services running on your host from inside a container.
  • For Postgres, make sure your volume mount path matches the image/version you’re using.