Docker Swarm Code Analysis Note (3)--swarm Create

Source: Internet
Author: User
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 .

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.