dongzhi5386 2017-12-13 21:45
浏览 387

Golang http.Get在容器中显示错误EOF

I have a golang script that calls an HTTP API. Everything works great when I run it on my development computer. Once I create the container and run it I get an EOF at the end of the URL on panic. I have read a lot of issues like this and have tried everyone I see. I added a ca-certificates.crt from my host machine to the container to /etc/ssl/certs/. I set the request close to true, I have disabled Keep-Alive and Compression. All of these steps worked for others on other posts. Any help appreciated.

I got my certfile from https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt

I am running go version go1.9.2 darwin/amd64 and the container is on a ubuntu 16.04 host.

client := &http.Client{Timeout: 30 * time.Second, Transport: &http.Transport{
    DisableCompression:true,
    DisableKeepAlives:  true,
}}

url := "https://myapiurl.com"
req, err := http.NewRequest("POST", url, bytes.NewBuffer(mybodybytes))
req.Close = true
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
    log.Panic(err) // Panics Here
}
defer resp.Body.Close()
...

Dockerfile:

 FROM scratch

    ADD ca-certificates.crt /etc/ssl/certs/

    ADD myservice /
    CMD ["/myservice"]
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统