Golang http.Get displays error EOF in Container

I have a golang script that calls a 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 the 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{
	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()

FROM scratch

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

ADD myservice /
CMD ["/myservice"]

This is not really a question about Go, but seems to be a problem about Docker containers. Perhaps someone here can help you, but I would try asking on a Docker mailinglist or similar forums.

Do you really have FROM scratch? I’m wondering that you even get thus far as you did and your program panics… You do not even have an operating system…

So lets start with these:

  1. Make sure your dockerfile does actually use the aforementioned base (ubuntu 16.04, or feel free to choose something better suited, see 2)
  2. Make sure that your build host and your docker container both have similar enough versions of the glibc or musl or whatever libc implementation you use.

When those are ensured, please report back with full code that is able to reproduce the problem (maybe minify your current project as much as possible), discriptions how to reproduce and also the full error message printed by the panic. At the current point in time I do not think that the full stack were necessary, but the error message at least.

Your Dockerfile looks quite similar to the second one in this article. So at least in theory, your setup should work.

To track down where your scenario breaks, can you please post a copy of the error message you get.

If possible, test the code against a plain HTTP host to verify if the problem is caused by TLS or by the certificates.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.