Did you know that you can navigate the posts by swiping left and right?

Remote TLS engine-API

engine-api is a favourite choice not only because Python sucks, but because it’s the official golang library coming from the Docker team. Surely I’ll forget this code soon, so I put it here, HTH others too.

Here, a remote TLS connection is set to the Docker Engine 1.12 bootstrapped with Machine. Code is rather self-explanatory.


package main

import (
	"github.com/docker/engine-api/client"
	"github.com/docker/engine-api/types"
	"github.com/docker/go-connections/tlsconfig"
	"golang.org/x/net/context"
	"net/http"
	"path/filepath"
)

func main() {
	var c *http.Client
	var host = "tcp://192.168.99.100:2376"
	var path = "/path/to/.docker/machine/machines/swarm/"

	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)
	}
}