engine-api icon indicating copy to clipboard operation
engine-api copied to clipboard

How to connect to a remote socket in docker/engine-api?

Open sms81 opened this issue 8 years ago • 2 comments

I want to retrieve all docker images of a remote machine, I was successful in returning the docker images of my local machine with the code provided in the Readme.md file, but the question is how can i retrieve docker images of a remote machine given its address,username, and password?

sms81 avatar Jun 30 '16 14:06 sms81

Currently the way to access a remote Docker host is via TCP. It is strongly recommended to use TLS.

Here are some docs to configure remote access for a Docker Engine: https://docs.docker.com/engine/security/https/. You can then connect using something like tcp://<ip>:2376 .

ehazlett avatar Jul 06 '16 18:07 ehazlett

@sms81 does this help?

    var c *http.Client
    var host = "tcp://192.168.99.100:2376"
    var path = "/path/to/.docker/machine/machines/mymachine/"

    securityOptions := tlsconfig.Options{
        CAFile:             filepath.Join(path, "ca.pem"),
        CertFile:           filepath.Join(path, "cert.pem"),
        KeyFile:            filepath.Join(path, "key.pem"),
        InsecureSkipVerify: true,
    }

    tlsc, err := tlsconfig.Client(securityOptions)
    if err != nil {
        return
    }

    c = &http.Client{
        Transport: &http.Transport{
            TLSClientConfig: tlsc,
        },
    }

    defaultHeaders := map[string]string{"User-Agent": "engine-api-cli-1.0"}
    cli, err := client.NewClient(host, "v1.24", c, defaultHeaders) // engine 1.12
    if err != nil {
        panic(err)
    }

fsoppelsa avatar Jul 13 '16 17:07 fsoppelsa