Home > Mobile >  Docker is inaccessible on localhost but works fine on 127.0.0.1
Docker is inaccessible on localhost but works fine on 127.0.0.1

Time:05-24

After working absolutely fine for at least a month, I am no longer able to access docker containers over localhost.

To reproduce:

  • Confirm nothing is running on port 80; both http://localhost and http://127.0.0.1 return Connection Refused
  • Open command prompt and run docker run -dp 80:80 docker/getting-started
  • http://localhost is still returns connection refused, but http://127.0.0.1 now redirects to http://127.0.0.1/tutorial/ and shows the docker tutorial page

I'm at a loss with how to fix this. The answers on here all seem to resolve with the configuration in docker-compose or docker run being wrong, or is some complex problem involving cross-container communication.

I have already tried system prune --all --volumes --force and there are no changes in the hosts file.

Some version numbers:

Windows 11: 22000.675

Docker Desktop: 4.8.2 (79419)

Engine: 20.10.14

CodePudding user response:

After uninstalling docker desktop, restarting, installing docker desktop and restarting, the issue has now resolved itself.

CodePudding user response:

This is typically a sign that the container or the docker engine is not handling ipv6 requests. Note that ipv6 is not supported with swarm ingress networking (you can get around that with pushing the port in host mode, which is not the same as host networking, a port published on the host is only reachable on that one host where the container is running).

You either need to track down which part of the docker and app stack is only listening on ipv4, or change the /etc/host entry for localhost to point to 127.0.0.1 instead of ::1. In the app, this could be listening on 0.0.0.0, publishing the port on something like 127.0.0.1:80, or not enabling ipv6 in the docker engine.

  • Related