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 ?

  • Boot2Docker: Connect to container over LAN
  • How can I mount a volume to docker container in OSX?
  • How to tell Docker to use dm/LVM backend for volumes instead of vfs
  • How to get docker container ID within Docker?
  • connecting tomcat webapp running in docker container to mysql
  • How to create postgis extension for postgresql in docker?
  • How to reach additional containers by the hostname after docker-compose scale?
  • Docker-client Java: How to keep instances running?
  • Building a non-uberjar Docker image with leiningen
  • sharing code between microservices
  • docker deploy image on multiple servers
  • Can not ping docker container from another host which is in the same LAN
  • 2 Solutions collect form web for “Adding services in different consul clients running on same host”

    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 \
    5. Add the other two nodes to the swarm as masters

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

      docker node ls

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

    Best practice for Consul, is to run consul one per HOST, and when you want to talk to consul, you always talk locally. In general, everything 1 consul node knows, every other consul node also knows. So you can just talk to your localhost consul ( and do everything you need to do. When you add services, you add them to the local consul node that has the service’s process on it. There are projects like Registrator ( That will automatically add services from running docker containers, which makes life easier.

    Overall, welcome to Consul, it’s great stuff!

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.