Search code examples
dockercluster-computingconsulconfiguration-managementetcd

Consul cluster automatic bootstrap on docker


I am working on conf management tools like etcd and consul. As I know etcd has discovery mechanism. I wonder does consul have something like that?

I am working on official consul docker image and when I set advertise IP's and join IP's there is no problem but I don't want to do this manually. Docker containers' Ip could change or some nodes could crash and you need new node to replace it. The situations like that how could I manage? I mean is there a possibility to join cluster without exactly know the nodes' Ip in the cluster?


Solution

  • You could start consul with docker swarm inside a subnet. Like this:

    docker network create --driver overlay --subnet 172.20.0.0/24 consul-net
    
    docker service create \
      --name consul \
      --publish 8500:8500 \
      --network consul-net \
      --replicas 3 \
      -e 'CONSUL_BIND_INTERFACE=eth0' \
      -e ‘CONSUL_LOCAL_CONFIG={“skip_leave_on_interrupt”:true}’ \
    consul agent -server -ui \
    -client=0.0.0.0 \
    -bootstrap-expect=3 \
    -data-dir=consul/data \
    -retry-join 172.20.0.3 \
    -retry-join 172.20.0.4 \
    -retry-join 172.20.0.5 \
    -retry-interval 5s
    

    You can also see this consul issue #66