Public Repository

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description


We need to assgin those param when we start a consul container:

  1. NETWORK_INTERFACE:the newtwork interface name, such as "etho", we use the name to get Cluster Addr
  2. CONSUL_SERVER: Is server agent or not
  3. SERVER_NUMS: the consul cluster server agent numbers
  4. DATACENTER: the consul cluster datacenter name
  5. CLIENT_IP: the consul cluster client ip, in order to separate from other consul cluster
  6. CONSUL_NODENAME: the consul node name
  7. SERVER_IP: the consul cluster server ip, by the way, we can join to a consul cluster

Running consul as server

$ docker run -d --name test --net host \
             -e "NETWORK_INTERFACE=bond1.101" \
             -e "CONSUL_SERVER=true" \
             -e "SERVER_NUMS=1" \
             -e "DATACENTER=dc_manage" \   

$ docker logs test 
[Warnning] Not assign CLIENT_IP, default use as consul Client Addr
[Warnning] Not assign CONSUL_NODENAME, default use hostname as consul nodename
==> WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode.
==> WARNING: Bootstrap mode enabled! Do not enable unless necessary
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Consul agent running!
         Node name: 'controller'
        Datacenter: 'dc_manage'
            Server: true (bootstrap: true)
       Client Addr: (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)
      Cluster Addr: (LAN: 8301, WAN: 8302)
    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
             Atlas: <disabled>

==> Log data will now stream in as it occurs:

    2016/11/10 02:15:37 [INFO] raft: Node at [Follower] entering Follower state
    2016/11/10 02:15:37 [INFO] serf: EventMemberJoin: controller
    2016/11/10 02:15:37 [INFO] consul: adding LAN server controller (Addr: (DC: dc_manage)
    2016/11/10 02:15:37 [INFO] serf: EventMemberJoin: controller.dc_manage
    2016/11/10 02:15:37 [INFO] consul: adding WAN server controller.dc_manage (Addr: (DC: dc_manage)
    2016/11/10 02:15:37 [ERR] agent: failed to sync remote state: No cluster leader
    2016/11/10 02:15:39 [WARN] raft: Heartbeat timeout reached, starting election
    2016/11/10 02:15:39 [INFO] raft: Node at [Candidate] entering Candidate state
    2016/11/10 02:15:39 [INFO] raft: Election won. Tally: 1
    2016/11/10 02:15:39 [INFO] raft: Node at [Leader] entering Leader state
    2016/11/10 02:15:39 [INFO] consul: cluster leadership acquired
    2016/11/10 02:15:39 [INFO] consul: New leader elected: controller
    2016/11/10 02:15:39 [INFO] raft: Disabling EnableSingleNode (bootstrap)
    2016/11/10 02:15:39 [INFO] consul: member 'controller' joined, marking health alive

$ docker exec -it test consul members
Node        Address           Status  Type    Build  Protocol  DC
controller  alive   server  0.6.3  2         dc_manage

Running consul as client

Just to assign the environment "CONSUL_SERVER=false". For example

$ docker run -d --name test --net host \
             -e "NETWORK_INTERFACE=bond1.101" \
             -e "CONSUL_SERVER=false" \
             -e "DATACENTER=dc_manage" \

$ docker exec -it test consul members
Node        Address           Status  Type    Build  Protocol  DC
controller  alive   client  0.6.3  2         dc_manage
Docker Pull Command