db:5432The API should use db:5432. Inside the Compose network, the API reaches Postgres by its service name and the container's own port.
"db:5433" is wrong because the 5433 mapping only applies to connections from the host. "localhost:5433" and "localhost:5432" are wrong because localhost inside the API container means the API container itself, not the database.
Read more
- Docker Compose (https://docs.docker.com/compose/)docs.docker.com
- Networking overview (https://docs.docker.com/engine/network/)docs.docker.com