diff --git a/config/config.go b/config/config.go index 190b0d2..ffb38eb 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ import ( type Metric string type BackendConfig struct { + DockerHost string `yaml:"DockerHost"` TLSCACert string `yaml:"TLSCACert"` TLSCert string `yaml:"TLSCert"` TLSKey string `yaml:"TLSKey"` @@ -49,6 +50,7 @@ func NewConfigFromFile(file string) (Config, error) { func (c Config) Print() { fmt.Println("Backend: ", c.Backend) fmt.Println("BackendConfig") + fmt.Println("\tDocker Host ", c.BackendConfig.DockerHost) fmt.Println("\tTLSCACert ", c.BackendConfig.TLSCACert) fmt.Println("\tTLSCert ", c.BackendConfig.TLSCert) fmt.Println("\tTLSKey ", c.BackendConfig.TLSKey) diff --git a/container/backend/docker/docker.go b/container/backend/docker/docker.go index 5d3f0ef..626b8ef 100644 --- a/container/backend/docker/docker.go +++ b/container/backend/docker/docker.go @@ -22,7 +22,6 @@ import ( ) const ( - DockerAPI = "unix:///var/run/docker.sock" DockerAPIVersion = "v1.23" ) @@ -35,6 +34,13 @@ func NewDockerBackend(c config.BackendConfig) (*Docker, error) { httpHeaders := map[string]string{ "User-Agent": fmt.Sprintf("kappa/%s", version.Version), } + + dockerHost := "unix:///var/run/docker.sock" + + if c.DockerHost != "" { + dockerHost = c.DockerHost + } + if c.TLSCert != "" && c.TLSKey != "" { tlsOptions := tlsconfig.Options{ CAFile: c.TLSCACert, @@ -42,6 +48,7 @@ func NewDockerBackend(c config.BackendConfig) (*Docker, error) { KeyFile: c.TLSKey, InsecureSkipVerify: c.AllowInsecure, } + config, err := tlsconfig.Client(tlsOptions) if err != nil { return nil, err @@ -49,7 +56,7 @@ func NewDockerBackend(c config.BackendConfig) (*Docker, error) { tr := &http.Transport{ TLSClientConfig: config, } - proto, addr, _, err := client.ParseHost(DockerAPI) + proto, addr, _, err := client.ParseHost(dockerHost) if err != nil { return nil, err } @@ -59,7 +66,7 @@ func NewDockerBackend(c config.BackendConfig) (*Docker, error) { } } - client, err := client.NewClient(DockerAPI, DockerAPIVersion, httpClient, httpHeaders) + client, err := client.NewClient(dockerHost, DockerAPIVersion, httpClient, httpHeaders) if err != nil { return nil, err } diff --git a/docs/examples/config.yml b/docs/examples/config.yml index 98b0faf..4fd7cce 100644 --- a/docs/examples/config.yml +++ b/docs/examples/config.yml @@ -1,10 +1,7 @@ --- backend: docker backend_config: - TLSCACert: "/etc/docker/ca.crt" - TLSCert: "/etc/docker/server.pem" - TLSKey: "/etc/docker/server.key" - AllowInsecure: false + DockerHost: "unix:///var/run/docker.sock" metrics: queue_length: "/usr/local/bin/queue_length.sh" reqsec: "/usr/local/bin/reqsec.sh"