diff --git a/agent.go b/agent.go index 2b2ecf4324..1ac4aa6e40 100644 --- a/agent.go +++ b/agent.go @@ -9,6 +9,7 @@ import ( "sort" "github.com/Sirupsen/logrus" + "github.com/docker/docker/pkg/stringid" "github.com/docker/go-events" "github.com/docker/libnetwork/datastore" "github.com/docker/libnetwork/discoverapi" @@ -246,10 +247,25 @@ func (c *controller) agentInit(bindAddrOrInterface, advertiseAddr string) error } keys, tags := c.getKeys(subsysGossip) + + // Make the hostname unique in the gossip cluster by appending a 12 + // byte random ID. Between distros there is no consensus if the + // hostname should be an FQDN or shortname. Limit the hostname to + // RFC 1123 compliant 63 bytes hostname, _ := os.Hostname() + id := stringid.TruncateID(stringid.GenerateRandomID()) + + var nodeName string + if len(hostname)+len(id) > 63 { + nodeName = hostname[:63-len(id)] + "-" + id + } else { + nodeName = hostname + "-" + id + } + logrus.Infof("Gossip cluster hostname ", nodeName) + nDB, err := networkdb.New(&networkdb.Config{ AdvertiseAddr: advertiseAddr, - NodeName: hostname, + NodeName: nodeName, Keys: keys, })