diff --git a/cli/cli.go b/cli/cli.go index 3a829a50da..48fe8178eb 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -114,7 +114,7 @@ func Run() { flStore, flStrategy, flFilter, flHosts, - flLeaderElection, flAddr, + flLeaderElection, flManageAdvertise, flTLS, flTLSCaCert, flTLSCert, flTLSKey, flTLSVerify, flHeartBeat, flEnableCors, @@ -125,7 +125,7 @@ func Run() { Name: "join", ShortName: "j", Usage: "join a docker cluster", - Flags: []cli.Flag{flAddr, flHeartBeat, flTTL}, + Flags: []cli.Flag{flJoinAdvertise, flHeartBeat, flTTL}, Action: join, }, } diff --git a/cli/flags.go b/cli/flags.go index f1fd2a18fd..70b7be61ff 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -32,13 +32,16 @@ var ( Value: homepath(".swarm"), Usage: "", } - flAddr = cli.StringFlag{ - Name: "addr", - Value: "127.0.0.1:2375", - Usage: "ip to advertise", - EnvVar: "SWARM_ADDR", + flJoinAdvertise = cli.StringFlag{ + Name: "advertise, addr", + Usage: "Address of the Docker Engine joining the cluster. Swarm managers MUST be able to reach Docker at this address.", + EnvVar: "SWARM_ADVERTISE", + } + flManageAdvertise = cli.StringFlag{ + Name: "advertise, addr", + Usage: "Address of the Swarm manager joining the cluster. Other swarm managers MUST be able to reach Swarm at this address.", + EnvVar: "SWARM_ADVERTISE", } - // hack for go vet flHostsValue = cli.StringSlice([]string{"tcp://127.0.0.1:2375"}) diff --git a/cli/join.go b/cli/join.go index 56a4324cb9..f56f85a076 100644 --- a/cli/join.go +++ b/cli/join.go @@ -20,6 +20,14 @@ func join(c *cli.Context) { log.Fatalf("discovery required to join a cluster. See '%s join --help'.", c.App.Name) } + addr := c.String("advertise") + if addr == "" { + log.Fatal("missing mandatory --advertise flag") + } + if !checkAddrFormat(addr) { + log.Fatal("--advertise should be of the form ip:port or hostname:port") + } + hb, err := time.ParseDuration(c.String("heartbeat")) if err != nil { log.Fatalf("invalid --heartbeat: %v", err) @@ -39,12 +47,6 @@ func join(c *cli.Context) { log.Fatal(err) } - addr := c.String("addr") - - if !checkAddrFormat(addr) { - log.Fatal("--addr should be of the form ip:port or hostname:port") - } - for { log.WithFields(log.Fields{"addr": addr, "discovery": dflag}).Infof("Registering on the discovery service every %s...", hb) if err := d.Register(addr); err != nil { diff --git a/cli/manage.go b/cli/manage.go index cf34ccce9f..657710e925 100644 --- a/cli/manage.go +++ b/cli/manage.go @@ -211,7 +211,15 @@ func manage(c *cli.Context) { router := api.NewRouter(cl, tlsConfig, c.Bool("cors")) if c.Bool("leader-election") { - setupLeaderElection(server, router, discovery, c.String("addr"), tlsConfig) + addr := c.String("advertise") + if addr == "" { + log.Fatal("--advertise address must be provided when using --leader-election") + } + if !checkAddrFormat(addr) { + log.Fatal("--advertise should be of the form ip:port or hostname:port") + } + + setupLeaderElection(server, router, discovery, addr, tlsConfig) } else { server.SetHandler(router) } diff --git a/discovery/README.md b/discovery/README.md index 91302587a3..3c9feeda83 100644 --- a/discovery/README.md +++ b/discovery/README.md @@ -26,7 +26,7 @@ Then we create each node and join them to the cluster. # on each of your nodes, start the swarm agent # doesn't have to be public (eg. 192.168.0.X), # as long as the swarm manager can access it. -$ swarm join --addr= token:// +$ swarm join --advertise= token:// ``` Finally, we start the Swarm manager. This can be on any machine or even @@ -95,7 +95,7 @@ On each of your nodes, start the Swarm agent. The node IP address doesn't have to be public as long as the swarm manager can access it. ```bash -swarm join --addr= etcd:/// +swarm join --advertise= etcd:/// ``` Start the manager on any machine or your laptop. @@ -127,7 +127,7 @@ On each of your nodes, start the Swarm agent. The node IP address doesn't need to be public as long as the Swarm manager can access it. ```bash -swarm join --addr= consul:/// +swarm join --advertise= consul:/// ``` Start the manager on any machine or your laptop. @@ -159,7 +159,7 @@ On each of your nodes, start the Swarm agent. The node IP doesn't have to be public as long as the swarm manager can access it. ```bash -swarm join --addr= zk://,/ +swarm join --advertise= zk://,/ ``` Start the manager on any machine or your laptop. diff --git a/docs/discovery.md b/docs/discovery.md index e551e9b939..df4b65aba0 100644 --- a/docs/discovery.md +++ b/docs/discovery.md @@ -26,7 +26,7 @@ Then we create each node and join them to the cluster. # on each of your nodes, start the swarm agent # doesn't have to be public (eg. 192.168.0.X), # as long as the swarm manager can access it. -$ swarm join --addr= token:// +$ swarm join --advertise= token:// ``` Finally, we start the Swarm manager. This can be on any machine or even @@ -95,7 +95,7 @@ On each of your nodes, start the Swarm agent. The node IP address doesn't have to be public as long as the swarm manager can access it. ```bash -swarm join --addr= etcd://,/ +swarm join --advertise= etcd://,/ ``` Start the manager on any machine or your laptop. @@ -127,7 +127,7 @@ On each of your nodes, start the Swarm agent. The node IP address doesn't need to be public as long as the Swarm manager can access it. ```bash -swarm join --addr= consul:/// +swarm join --advertise= consul:/// ``` Start the manager on any machine or your laptop. @@ -159,7 +159,7 @@ On each of your nodes, start the Swarm agent. The node IP doesn't have to be public as long as the swarm manager can access it. ```bash -swarm join --addr= zk://,/ +swarm join --advertise= zk://,/ ``` Start the manager on any machine or your laptop. diff --git a/docs/scheduler/filter.md b/docs/scheduler/filter.md index 638a8c71de..053208fdcd 100644 --- a/docs/scheduler/filter.md +++ b/docs/scheduler/filter.md @@ -41,14 +41,14 @@ For instance, let's start `node-1` with the `storage=ssd` label: ```bash $ docker -d --label storage=ssd -$ swarm join --addr=192.168.0.42:2375 token://XXXXXXXXXXXXXXXXXX +$ swarm join --advertise=192.168.0.42:2375 token://XXXXXXXXXXXXXXXXXX ``` Again, but this time `node-2` with `storage=disk`: ```bash $ docker -d --label storage=disk -$ swarm join --addr=192.168.0.43:2375 token://XXXXXXXXXXXXXXXXXX +$ swarm join --advertise=192.168.0.43:2375 token://XXXXXXXXXXXXXXXXXX ``` Once the nodes are registered with the cluster, the master pulls their respective diff --git a/scheduler/filter/README.md b/scheduler/filter/README.md index 494312997d..2f925ab235 100644 --- a/scheduler/filter/README.md +++ b/scheduler/filter/README.md @@ -41,14 +41,14 @@ For instance, let's start `node-1` with the `storage=ssd` label: ```bash $ docker -d --label storage=ssd -$ swarm join --addr=192.168.0.42:2375 token://XXXXXXXXXXXXXXXXXX +$ swarm join --advertise=192.168.0.42:2375 token://XXXXXXXXXXXXXXXXXX ``` Again, but this time `node-2` with `storage=disk`: ```bash $ docker -d --label storage=disk -$ swarm join --addr=192.168.0.43:2375 token://XXXXXXXXXXXXXXXXXX +$ swarm join --advertise=192.168.0.43:2375 token://XXXXXXXXXXXXXXXXXX ``` Once the nodes are registered with the cluster, the master pulls their respective diff --git a/test/integration/helpers.bash b/test/integration/helpers.bash index 816df06191..4c6085dfbd 100644 --- a/test/integration/helpers.bash +++ b/test/integration/helpers.bash @@ -117,7 +117,7 @@ function swarm_join() { for ((i=current; i < nodes; i++)); do local h="${HOSTS[$i]}" echo "Swarm join #${i}: $h $addr" - "$SWARM_BINARY" -l debug join --heartbeat=1s --ttl=10s --addr="$h" "$addr" & + "$SWARM_BINARY" -l debug join --heartbeat=1s --ttl=10s --advertise="$h" "$addr" & SWARM_JOIN_PID[$i]=$! done }