Search code examples
dockernetwork-programmingdocker-composedocker-swarmdocker-network

Host Network on Swarm: Service Discovery and Communication with other Services


I’ve been working with Docker Swarm and have run into an issue regarding service discovery. Specifically, one of my services is utilizing the “host network”, and I’ve learned from a discussion on this GitHub issue that I’m unable to simultaneously include my service in the overlay network.

This situation has created a significant roadblock for me because it has prevented the use of Docker Swarm’s DNSRR feature. Previously, I leveraged DNSRR for service discovery, particularly for identifying the IPs of active tasks.I am seeking a solution or feature that allows me to query all the tasks currently running under the service, including their private and/or public IPs.

Furthermore, when my service was attached to the overlay network, I was able to directly access other services using their DNS names. However, now that my service isn’t a part of the overlay network, I am compelled to use private IPs, which isn’t optimal.

Could anyone point me in the direction of a solution or workaround for these challenges? Any advice or insights would be greatly appreciated.

Thank you in advance for your help.

I have tried to add my service into the overlay network but it failed


Solution

  • Since you cannot have both host and another network because of a limitation of Docker Swarm. What you can do is the following assuming you have traefik.

    Run two services:

    1. traefik for external

      a. runs and listens to port 80/443 on host mode networking.

      b. it is only on host network

      c. I'm assuming you'd have a reroute so HTTP goes to HTTPS d. Route HTTPS over to the other traefik

    2. traefik for Docker swarm overlay

      a. runs on overlay network

      b. get the real IP from external-traefik

      c. exposed on a different port e.g. 8443