Inside a normally isolated container, localhost points back into that container. On Docker Desktop, host.docker.internal is the documented name for reaching a service on the host. Another Compose service should usually be addressed by its service name and container port.
Inspect the boundary before changing the service
The commands below use placeholder names. They illustrate a diagnostic workflow and were not run against a live container in this review. Match the Docker context and project before inspecting your own service.
# Read-only inspection; replace demo with your actual container name.
docker context show
docker inspect demo --format '{{json .NetworkSettings.Networks}}'
docker inspect demo --format '{{json .HostConfig.ExtraHosts}}'
# Example application URL on Docker Desktop:
# http://host.docker.internal:8000/What to compare
Write down the caller, destination and listening port before changing a URL. Browser-to-container, container-to-host and container-to-container are different routes. Publishing port 8000 on the host does not make localhost:8000 inside every other container point at that host. A service name such as db is meaningful on the shared Compose network; it is not generally a hostname for a browser outside that network.
Choose the next action
On Desktop, test the documented host name using the client already available in your container, then check the host application listener and firewall if the connection still fails. On standalone Linux Engine, do not assume the Desktop name is preconfigured. An explicit host-gateway mapping is one supported pattern in Engine, but must match your deployment policy and network. If Docker uses a remote context, identify the daemon host first: your laptop and the Docker host may be different machines.
Limits and verification
These diagnostic commands do not change networking. This review did not start Docker or prove connectivity to a running service. Rootless, host networking, VPNs and IPv6 can change the route. Avoid switching to host networking as a general first fix; establish the intended connection boundary before changing isolation.
Related: Docker EXPOSE Does Not Publish a Host Port: Inspect the Mapping and Listener.
Official Docker documentation checked November 10, 2026 (KST). Docker Compose 2.35.1 configuration parsing was available, but the Docker daemon was not running. These pages do not claim a live container connectivity, storage, health or recovery test.