Search code examples
dockerdocker-swarm

Docker Swarm on native hosts


The best article using native hosts for Docker swarm I found, still has me without a working cluster!

The commands used were as follows:

Pre Setup:
    service docker stop
    docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
    docker run -d -p 8500:8500 --name=consul -server -bootstrap

Cluster Setup:
    docker run -d -p 4000:4000 swarm manage -H :4000 --replication --advertise <manager0_ip>:4000 consul://<consul_ip>:8500

Agent Setup:
    docker run -d swarm join --advertise=<node_ip>:2375 consul://<consul_ip>:8500

To test, it says to run this command on the manager node:

docker -H :4000 run -itd ubuntu

However, when I do that I get:

docker: Error response from daemon: No healthy node available in the cluster.

As a result I have this set of questions:

  1. There are 3 different ip addresses listed, I created a bash shell on the consul container and obtained that one. Can anyone clarify what the specifics on precisely how to get the "manager0_ip" and "node_ip"?

  2. The port usage above between 2375 and 4000 is confusing. If the swarm manage advertises on 4000, why is the swarm join on port 2375? Also, is the use of ='s correct in the second advertise case? It is not on the first.

  3. No swarm init was mentioned in the linked article. Can anyone comment on the semantics there? When is that needed and when not?


Solution

  • Docker swarm is now integrated within the docker engine, in version 1.12. How this new feature works is detailed here:

    https://docs.docker.com/engine/swarm/

    Reading this will explain how the new "docker swarm", "docker node" and "docker service" commands work.

    Setting up a swarm has never been so easy. So throw away that link, upgrade to version 1.12 and try again :-)

    Example

    Run the following command on the manager node:

    docker swarm init --advertise-addr $MANAGER_IP
    

    This will print the following sample output

    Swarm initialized: current node (00ehj7mi2eaiix2uy46hn9ja8) is now a manager.
    
    To add a worker to this swarm, run the following command:
        docker swarm join \
        --token SWMTKN-1-4tn8u9ywprdez0u2qfmv1lv0iq0x4r4aiwexgjg6gi7s63dqrw-192xx5jwhrxpy1q08xmb1dwyy \
        192.168.1.18:2377
    
    To add a manager to this swarm, run the following command:
        docker swarm join \
        --token SWMTKN-1-4tn8u9ywprdez0u2qfmv1lv0iq0x4r4aiwexgjg6gi7s63dqrw-9ow8agcir34zovprrt512rbz3 \
        192.168.1.18:2377
    

    See how it provides the commands to add additional managers and workers to the swarm? Just run these commands on each additional node to expand your swarm.