5

I have very weird problem:

I have the swarm cluster and one of my service have wrong ip:

$ docker service inspect nginx_backend | grep Addr
                    "Addr": "10.0.0.107/24"

From any container in the cluster:

/ # ping nginx_backend
PING nginx_backend (10.0.0.107): 56 data bytes
64 bytes from 10.0.0.107: seq=0 ttl=64 time=0.057 ms
64 bytes from 10.0.0.107: seq=1 ttl=64 time=0.061 ms
64 bytes from 10.0.0.107: seq=2 ttl=64 time=0.064 ms
64 bytes from 10.0.0.107: seq=3 ttl=64 time=0.083 ms
^C
--- nginx_backend ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.057/0.066/0.083 ms

But in the server which hosted nginx_backend container:

root@backend:~# docker inspect nginx_backend.1.myzy10psfdl9r4jljrsz5zd5t | grep IPv4
                        "IPv4Address": "10.0.0.87"

And when some service try connect by name it got connect error, but if I manually put record like 10.0.0.87 nginx_backend to /etc/hosts inside a container, it have successful connect.

What I did wrong?)

Kealman
  • 93
  • 1
  • 7

1 Answers1

3

Docker creates (by default) a Virtual IP (VIP) for each service. That's the 10.0.0.107. It then balances requests between the backend containers. In the second example (10.0.0.87) you're seeing the IP address of one of the containers. That's routable within Docker as well (which is why hitting the IP works). However the name (nginx_backend.1.myzy10psfdl9r4jljrsz5zd5t) is not DNS resolvable so that's why that fails.

You can find a list of the 'backing' containers for a service by doing a DNS lookup on tasks.nginx_backend.

Some more background here: https://docs.docker.com/network/overlay/

johnharris85
  • 13,054
  • 4
  • 43
  • 49
  • 2
    Thank you for your answer! Yes, you right, I forget about it. But I've tried connect from another service by DNS resolvable name like `nginx_backend` as it name (at least other service see each other with service name). But this service don't answer. I think it may another problem instead of I wrote. But may be you know where to I have to see?) – Kealman May 29 '18 at 18:59
  • @Kealman, probably you meat issue https://github.com/moby/moby/issues/30487 which was fixed in release 18.06 – heroin Nov 22 '18 at 15:57