Get wrong IP when using docker network swarm

Hello eveyryone!

I am having some problem when using overlay network in docker.

I create a network named “my-overlay” and run a service named “my-service” with only one node.

when I ping my-service_my-service I get 10.0.50.192 while real ip of this node is 10.0.50.191.

When I curl my-service_my-service I get this reponse:

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.

Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.


Apache/2.4.29 (Ubuntu) Server at 10.0.50.191 Port 5000

How can I fix it?

What you experience is the difference between the service ip and the container ip. Swarm routes a publised port towards the service ip, which acts as a virtual ip and is responsible to forward the traffic to the containers. vip is the default behavior for published ports. You can change it to mode: dnsrr to let the service ip always lookup and return the container ip(s).

Did you try to use {servicename}.{networkname} instead of the servicename? Is you traffic routed thru a containerized reverse proxy?

2 Likes

Thank you so much. It succeeds

And I have another question with network in docker swarm
In this picture

I don’t know clearly about Engine DNS Server. Where can I edit DNS server?

In my case, task1.myservice and task2.myservice is a service using overlay network. If I let node manager to become DNS server, it doesn’t know internal network of myservice to load balancing.

Please answer me this question. Thanks so much!

I can not see your picture.

Each custom bridge/overlay network has its own dns server, which is not designed to be modified outside of docker commands or the compose.yml.

You can affect dns with following configuration items:

services:
  some-service:
    networks:
      some-network:
        aliases:
         - alias1
         - alias2
         ...

Appart of that, you can inject name resolution into a containers /etc/hosts:

extra_hosts:
 - "somehost:162.242.195.82"
 - "otherhost:50.31.209.229"