docker-swarm

Can't create Docker Swarm because of connection failure


  1. Target: Creating a Docker Swarm

  2. Condition:

    • Host A: Ubuntu 23.10
    • Host B: Mac Sonoma 14.1.2
  3. Operation:

    • In Host A:
      docker swarm init
      
    • In Host B:
      docker swarm join --token SWMTKN-1-3o2m78qf57hy2zikfx8p2yc7hrn63edlmlixwrq7bh28xws7zx-9oirn0wh3mbrdui3kcwytl560 192.168.65.9:2377
      
  4. Error:

    Error response from daemon: rpc error: code = Unavailable desc = connection error:
    desc = "transport: Error while dialing dial tcp 192.168.65.9:2377: connect: no route to host"
    
  5. What I've done so far:

    • Installed firewalld on Ubuntu Host A, but for unknown reason it caused system crash. I guess this is because Ubuntu 23.10 doesn't support firewalld anymore.
    • Use ufw command to open communication port on Ubuntu Host A, but it doesn't work.
  6. Asking for help: I saw other people can easily run the "docker swarm join" command in the tutorial. Why I got this problem? Any one can help me out? Really appreciate your help.


Solution

  • You need to open several ports for the communication (On A as well ass B hosts):

    As Docker documentations says:

    Furthermore:

    Set UFW config (Or disable the UFW as you mentioned in your question):

    ufw allow 22/tcp
    ufw allow 2376/tcp
    ufw allow 2377/tcp
    ufw allow 7946/tcp
    ufw allow 7946/udp
    ufw allow 4789/udp
    ufw reload
    ufw enable
    systemctl restart docker
    

    You can check the IpTables configuration as well based on this documentation: https://www.digitalocean.com/community/tutorials/how-to-configure-the-linux-firewall-for-docker-swarm-on-ubuntu-16-04

    BUT, The "Docker for Mac" uses different networking as Linux based and that can cause turbulence in Docker Swarm. Here is a ticket for it: https://github.com/moby/swarmkit/issues/1146#issuecomment-231412874

    Based on the above ticket the Mac can run only single-node Swarm right now. (I didn't find fix for it)