This is a creation in
Article, where the information may have evolved or changed.
Docker SwarmThe create command code is simple:
func create(c *cli.Context) { if len(c.Args()) != 0 { log.Fatalf("the `create` command takes no arguments. See '%s create --help'.", c.App.Name) } discovery := &token.Discovery{} discovery.Initialize("", 0, 0, nil) token, err := discovery.CreateCluster() if err != nil { log.Fatal(err) } fmt.Println(token)}
and token.CreateCluster() the implementation of the function:
// CreateCluster returns a unique cluster tokenfunc (s *Discovery) CreateCluster() (string, error) { resp, err := http.Post(fmt.Sprintf("%s/%s", s.url, "clusters"), "", nil) if err != nil { return "", err } defer resp.Body.Close() token, err := ioutil.ReadAll(resp.Body) return string(token), err}
is actually to https://discovery.hub.docker.com/v1/clusters send a https post request, and then get the only one token , use this token to create and manage cluster .