On swarm I can only access the service by IP, not by hostnames

If I run Portainer with docker command as described in the installation, it works well and I can access it as 127.0.0.1:9000 or localhost:9000. But, if I launch it as a Swarm service, using the docker-stack.yml from Portainer Github, I can only access it as 127.0.0.1:9000, when I try localhost:9000 the browser will load forever, no page and no errors. I tryed to run a NGINX image and it acted the same way.

Any ideas why I can’t access Swarm service by hostname but only by IP?

Command to deploy the Portainer service yml:

docker stack deploy --compose-file=docker-stack.yml portainer

System:

$ uname -a
Linux LaptopOpressor 5.7.0-3-MANJARO #1 SMP PREEMPT Wed Jun 3 03:15:33 UTC 2020 x86_64 GNU/Linux

$ docker version
Client:
Version: 19.03.11-ce
API version: 1.40
Go version: go1.14.3
Git commit: 42e35e61f3
Built: Tue Jun 2 15:09:26 2020
OS/Arch: linux/amd64
Experimental: false

Server:
Engine:
Version: 19.03.11-ce
API version: 1.40 (minimum version 1.12)
Go version: go1.14.3
Git commit: 42e35e61f3
Built: Tue Jun 2 15:09:05 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.3.4.m
GitCommit: d76c121f76a5fc8a462dc64594aea72fe18e1178.m
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683

$ docker network ls
NETWORK ID NAME DRIVER SCOPE
320c14bfb8c9 bridge bridge local
0e8e95d088fb docker_gwbridge bridge local
3f96345af20a host host local
o35agcgjnqtc ingress overlay swarm
04630a9a14fd none null local
ji1fc3gag66u portainer_agent_network overlay swarm

$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-USER all – anywhere anywhere
DOCKER-INGRESS all – anywhere anywhere
DOCKER-ISOLATION-STAGE-1 all – anywhere anywhere
ACCEPT all – anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all – anywhere anywhere
ACCEPT all – anywhere anywhere
ACCEPT all – anywhere anywhere
ACCEPT all – anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all – anywhere anywhere
ACCEPT all – anywhere anywhere
DROP all – anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain DOCKER (2 references)
target prot opt source destination

Chain DOCKER-INGRESS (1 references)
target prot opt source destination
ACCEPT tcp – anywhere anywhere tcp dpt:cslistener
ACCEPT tcp – anywhere anywhere state RELATED,ESTABLISHED tcp spt:cslistener
ACCEPT tcp – anywhere anywhere tcp dpt:irdmi
ACCEPT tcp – anywhere anywhere state RELATED,ESTABLISHED tcp spt:irdmi
RETURN all – anywhere anywhere

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all – anywhere anywhere
DOCKER-ISOLATION-STAGE-2 all – anywhere anywhere
RETURN all – anywhere anywhere

Chain DOCKER-ISOLATION-STAGE-2 (2 references)
target prot opt source destination
DROP all – anywhere anywhere
DROP all – anywhere anywhere
RETURN all – anywhere anywhere

Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all – anywhere anywhere

If its also happening with other containers, this is not a Portainer issue.

I believe you are experiencing this issue https://forums.docker.com/t/google-chrome-and-localhost-in-swarm-mode/32229/10

1 Like

Thank you so much to point me in the right direction.
I found out that Swarm does not properly support IPv6 yet.
My solution was to disable IPv6 support system wide.
Now localhost:9000 is working within Swarm too.