Problem
I have a Docker service container exposed to *:8080
.
- I cannot access the container through
localhost:8080
. Chrome /curl
hangs up indefinitely. - But I can access the container if I use any other local IP, such as
127.0.0.1
This is tripping me up because in my hosts
file, localhost
redirects to 127.0.0.1
.
Why is this happening? And is it IPv4/IPv6 dual-stack related somehow?
Environment
I am on PopOS (Ubuntu-based), with Docker Swarm enabled.
I am using this test stack file, traefik.docker-compose.yml
:
version: '3'
services:
reverse-proxy:
image: traefik # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
To run the stack, I use:
docker stack deploy -c traefik.docker-compose.yml traefik
Once the service is up, I confirm that it is listening to 8080
through 2 ways:
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
4ejfsvenij3p traefik_reverse-proxy replicated 1/1 traefik:latest *:80->80/tcp, *:8080->8080/tcp
sudo ss -pnlt | grep 8080
LISTEN 3 128 *:8080 *:* users:(("dockerd",pid=2119,fd=45))
For reference, here is the contents of my /etc/hosts
:
127.0.0.1 localhost
::1 localhost ipv6-localhost
127.0.1.1 pop-os.localdomain pop-os pop1810x220
I just use curl
for the tests:
- Works:
curl http://127.0.0.1:8080
- Hangs up:
curl http://localhost:8080