dream2891 2016-11-14 22:21
浏览 182
已采纳

Docker API调用返回“服务器向HTTPS客户端提供了HTTP响应”

I have the following Code and a Call to the API returns an error as follows, I hve also pasted Docker Daemon command below. I have tried a few combinations from HTTP/ HTTPS / TCP with / without TLS.

Where could I be wrong here?

"panic: An error occurred trying to connect: Get https://172.28.8.212:2375/v1.24/containers/json?limit=0: http: server gave HTTP response to HTTPS client "

func main() {
    var headers map[string]string

    tr := &http.Transport{
        TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
    }

    cl := &http.Client{Timeout: time.Minute}

    cli, err := client.NewClient("tcp://172.28.8.212:2375", "1.24", cl, headers)
    if err != nil {
        panic(err)
    }

    containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
    if err != nil {
        panic(err)
    }

    for _, container := range containers {
        fmt.Printf("%s %s
", container.ID[:10], container.Image)
    }
}

My Docker Daemon is started as follows

[Unit]
Description = Docker Service Daemon
[Service]
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://172.28.8.211:8500
  • 写回答

1条回答 默认 最新

  • doupin1073 2016-11-30 23:55
    关注
    func main() {
        var headers map[string]string
    
        tr := &http.Transport{} <---- Note the difference here. 
    
        tr.Dial = func(proto, addr string) (net.Conn, error) {
            fmt.Println("Dial called")
            conn, err := net.DialTimeout(proto, addr, time.Minute)
            if err != nil {
                fmt.Println("There was  an err", err)
            }
            return conn, err
        }
    
        cl := &http.Client{Transport: tr}
        cli, err := client.NewClient("http://x.y.z.w:2376", "1.24", cl, headers)
        if err != nil {
            panic(err)
        }
    
        containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
        if err != nil {
            panic(err)
        }
    
        for _, container := range containers {
            fmt.Printf("%s %s
    ", container.ID[:10], container.Image)
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3