使用Go docker SDK

时间:2017-10-17 12:08:26

标签: docker go docker-machine

我有一个golang二进制文件,它使用TLS与远程docker守护进程通信。二进制文件在本地机器上成功运行。但是当在docker ubuntu容器中运行这个二进制文件时,tls配置失败。它出现以下错误:

    /usr/local/go/src/crypto/x509/cert_pool.go:96 +0x6b
crypto/x509.(*CertPool).AppendCertsFromPEM(0x0, 0xc4202bd4c8, 0x0, 0x200, 0xac8)
    /usr/local/go/src/crypto/x509/cert_pool.go:128 +0x161
github.com/docker/go-connections/tlsconfig.certPool(0xc420240de0, 0x18, 0xc42018bc00, 0x51bbca, 0xc420240e20, 0x19)
    /media/atom/lighthouse/gowork/src/github.com/docker/go-connections/tlsconfig/config.go:105 +0x283
github.com/docker/go-connections/tlsconfig.Client(0xc420240de0, 0x18, 0xc420240e00, 0x1a, 0xc420240e20, 0x19, 0x0, 0x0, 0x0, 0x0, ...)
    /media/atom/lighthouse/gowork/src/github.com/docker/go-connections/tlsconfig/config.go:199 +0x25a

二进制文件使用github.com/docker/docker/client,官方docker golang SDK。

1 个答案:

答案 0 :(得分:1)

我不知道为什么你发布了什么,但是来自以下程序的堆栈跟踪看起来与你所看到的相似。解决方案很可能是确保您的*x509.CertPool不能nil

package main

import (
  "fmt"
  "crypto/x509"
)

func main() {
  var cp *x509.CertPool
  cert := &x509.Certificate{}
  cp.AddCert(cert)
  fmt.Println("AddCert succeeded")
}

Playground link