Start here. This is the direct spoken answer to practice first.
Why this question matters
Inside a container, localhost refers to that container. The API must bind to an address reachable through its container network, and dependencies are addressed by their service identity rather than the host's loopback address.
I first separate the application listen port from the host or platform port. The ASP.NET Core process might listen on 0.0.0.0:8080, while Docker or an ingress publishes another external port. For dependencies on the same network, I use the service DNS name and internal port. host.docker.internal can be useful for local host access on supported platforms, but it is not a portable production service-discovery strategy.