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.