Docker Swarm Code Analysis Note (one)--engine.connect

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Engine.Connect()method is used to complete the Docker engine connection work:

 //Connect would initialize a connection to the Docker daemon running on the//host, gather machine specs (memor Y, CPU, ...) and monitor state Changes.func (e *engine) Connect (config *tls. Config) Error {host, _, Err: = Net. Splithostport (E.ADDR) if err! = Nil {return err} Addr, err: = Net. RESOLVEIPADDR ("IP4", host) if err! = Nil {return err} E.ip = addr. Ip. String () c, err: = Dockerclient. Newdockerclienttimeout ("tcp://" +e.addr, config, time. Duration (requesttimeout), settcpusertimeout) if err! = Nil {return ERR}//Use HTTP Client used by Docke Rclient to create ENGINE-API client apiclient, err: = Engineapi. Newclient ("tcp://" +e.addr, "", c.httpclient, nil) if err! = Nil {return err} return E.connectwithclient ( C, apiclient)}  

Engine.Connect()Two additional items were used Docker : Dockerclient and Engine-api. The first call is to dockerclient.NewDockerClientTimeout("tcp://"+e.Addr, config, time.Duration(requestTimeout), setTCPUserTimeout) generate a DockerClient struct:

type DockerClient struct {    URL           *url.URL    HTTPClient    *http.Client    TLSConfig     *tls.Config    monitorStats  int32    eventStopChan chan (struct{})}

Then the DockerClient.HTTPClient incoming engineapi.NewClient() function, as engine-api the http.Client HTTP transmission carrier of the request. Finally call Engine.ConnectWithClient() Docker engine the connection to get the Docker information.

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.