This is a creation in Article, where the information may have evolved or changed.
Docker SwarmThe join definition of the command:
{ Name: "join", ShortName: "j", Usage: "Join a docker cluster", Flags: []cli.Flag{flJoinAdvertise, flHeartBeat, flTTL, flJoinRandomDelay, flDiscoveryOpt}, Action: join, },
flHeartBeatThe default value is 60s , and the flTTL default value is 180s :
flHeartBeat = cli.StringFlag{ Name: "heartbeat", Value: "60s", Usage: "period between each heartbeat",}flTTL = cli.StringFlag{ Name: "ttl", Value: "180s", Usage: "set the expiration of an ephemeral node",}
joinThe core code of the function:
......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 { log.Error(err) } time.Sleep(hb)}......
token.RegisterFunction implementation:
func (s *Discovery) Register(addr string) error { buf := strings.NewReader(addr) resp, err := http.Post(fmt.Sprintf("%s/%s/%s?ttl=%d", s.url, "clusters", s.token, uint64(s.ttl.Seconds())), "application/json", buf) if err != nil { return err } resp.Body.Close() return nil}
joinThe command is actually every heartbeat time (for example 60s ), to https://discovery.hub.docker.com/v1/clusters/token/ttl=180 ( ttl take the default value), register the current Docker address ( IP:PORT ).