Docker Community Forums

Share and learn in the Docker community.

How to pass node name to other nodes


(Edoardo) #1

Hi all,

I am using consul (which I know virtually nothing about - but am learning) to explain the issue I have.

I created a network so that I could track what was happening with the network side of things

docker network create --driver=bridge --subnet=10.50.100.0/24 --gateway=10.50.100.254 my-net

I then create the consul “master”

docker run --net=my-net -d --name node1 -h node1 progrium/consul -server -bootstrap-expect 3

the consul master is named node1 but when I try and pass that node name to other nodes, it fails be it using docker run or docker compose

docker run --rm -it --net=my-net --name node2 -h node2 progrium/consul -server -join node1
==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1
==> Starting raft data migration...
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Joining cluster...
==> lookup node1: no such host

or

node1:
  image: progrium/consul:latest
  name: node1
  net: my-net
  ports:
    - 8400:8400
    - 8500:8500
    - 53:53
  command: "-server -bootstrap-expect 3 -ui-dir /ui"
node2:
  image: progrium/consul:latest
  name: node2
  net: my-net
  ports:
    - 8400
    - 8500
    - 8600
  command: "-server -join node1"

but if I mention the IP, it all works perfectly

docker run --rm -it --net=my-net --name node2 -h node2 progrium/consul -server -join 10.50.100.1
==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1
==> Starting raft data migration...
==> Starting Consul agent...
==> Starting Consul agent RPC...
==> Joining cluster...
    Join completed. Synced with 1 initial agents
==> Consul agent running!
         Node name: 'node2'
        Datacenter: 'dc1'
            Server: true (bootstrap: false)
       Client Addr: 0.0.0.0 (HTTP: 8500, HTTPS: -1, DNS: 53, RPC: 8400)
      Cluster Addr: 10.50.100.2 (LAN: 8301, WAN: 8302)
    Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false
             Atlas: <disabled>

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

    2015/11/11 18:28:23 [INFO] serf: EventMemberJoin: node2 10.50.100.2
    2015/11/11 18:28:23 [INFO] serf: EventMemberJoin: node2.dc1 10.50.100.2
    2015/11/11 18:28:23 [INFO] raft: Node at 10.50.100.2:8300 [Follower] entering Follower state
    2015/11/11 18:28:23 [INFO] consul: adding server node2 (Addr: 10.50.100.2:8300) (DC: dc1)
    2015/11/11 18:28:23 [INFO] consul: adding server node2.dc1 (Addr: 10.50.100.2:8300) (DC: dc1)
    2015/11/11 18:28:23 [INFO] agent: (LAN) joining: [10.50.100.1]
    2015/11/11 18:28:23 [INFO] serf: EventMemberJoin: node1 10.50.100.1
    2015/11/11 18:28:23 [INFO] agent: (LAN) joined: 1 Err: <nil>
    2015/11/11 18:28:23 [ERR] agent: failed to sync remote state: No cluster leader
    2015/11/11 18:28:23 [INFO] consul: adding server node1 (Addr: 10.50.100.1:8300) (DC: dc1)
    2015/11/11 18:28:25 [WARN] raft: EnableSingleNode disabled, and no known peers. Aborting election.

node2 has node1 mentioned in the /etc/hosts file, they are both part of the same network and I can ping them, I just can not seem to pass “node1” as part of a command to the consul agent.

Am I doing something wrong? How would you do it so that you can have a single yams file starting both nodes without knowing what the IP will be for the master node?

Thanks!