Search code examples
dockerconsul

Adding services in different consul clients running on same host


I've followed the section of in Testing a Consul cluster on a single host using consul. Three consul servers are successfully added and running in same host for testing purpose. Afterwards, I've also followed the tutorial and created a consul client node4 to expose ports. Is it possible to add more services and bind to one of those consul clients ?


Solution

  • Use the new 'swarm mode' instead of the legacy Swarm. Swarm mode doesn't require Consul. Service discovery and key/value store is now part of the docker daemon. Here's how to create a 3 nodes High Available cluster (3 masters).

    1. Create three nodes

      docker-machine create --driver vmwarefusion node01
      docker-machine create --driver vmwarefusion node02
      docker-machine create --driver vmwarefusion node03
      
    2. Find the ip of node01

      docker-machine ls
      
    3. Set one as the initial swarm master

      docker $(docker-machine config node01) swarm init --advertise-addr <ip-of-node01>
      
    4. Retrieve the token to let other nodes join as master

      docker $(docker-machine config node01) swarm join-token manager
      

      This will print out something like

      docker swarm join \
      --token SWMTKN-1-0siwp7rzqeslnhuf42d16zcwodk543l99liy0wuq1mern8s8u9-8mbsrxzu9mgfw7x6ehpxh0dof \
      192.168.40.144:2377
      
    5. Add the other two nodes to the swarm as masters

      docker $(docker-machine config node02) swarm join \
      --token SWMTKN-1-0siwp7rzqeslnhuf42d16zcwodk543l99liy0wuq1mern8s8u9-8mbsrxzu9mgfw7x6ehpxh0dof \
      192.168.40.144:2377
      
      docker $(docker-machine config node03) swarm join \
      --token SWMTKN-1-0siwp7rzqeslnhuf42d16zcwodk543l99liy0wuq1mern8s8u9-8mbsrxzu9mgfw7x6ehpxh0dof \
      192.168.40.144:2377
      
    6. Examine the swarm

      docker node ls
      

    You should now be able to shutdown the leader node and see another pick up as manager.