A Go service in a container cannot reach the internet and reports i/o timeout
dial tcp: i/o timeoutShort answer
The container could not get an answer from the network in time. Two documented causes: it inherited DNS settings from the host that do not work inside Docker, or the network only allows outbound traffic through a proxy the Docker daemon does not know about. Test name lookup and a plain request from inside the container first.
Fix it fast
1Find out which cause you have
Compare the DNS servers the host uses with the ones the container received. Servers that differ or cannot be reached from inside Docker point to the first cause; matching, working servers point to the proxy.
cat /etc/resolv.conf docker run --rm busybox cat /etc/resolv.conf2Match what you see, then jump to its fix
What does the error look like?
dial tcp: i/o timeoutthe same call works on the host but times out inside the container
Cause 1 of 2
The container's DNS servers are wrong or unreachable
1Check
By default a container inherits the DNS settings of the host's /etc/resolv.conf. On user-defined networks it uses Docker's embedded DNS server at 127.0.0.11, which forwards to the host's configured servers.
cat /etc/resolv.conf
docker run --rm busybox cat /etc/resolv.conf2Fix
Give the container a working DNS server with --dns, once per server.
docker run --rm --dns 1.1.1.1 --dns 8.8.8.8 my-go-app3Verify
Start the service with the same flags; the call that timed out now succeeds.
docker run --rm --dns 1.1.1.1 my-go-appConfirmed by docs.docker.com
Cause 2 of 2
Outbound traffic must go through a proxy the daemon does not use
1Check
The Docker daemon reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY at startup, or the proxies block in daemon.json. Settings in daemon.json are ignored by Docker Desktop, which has its own proxy settings.
sudo cat /etc/docker/daemon.json2Fix
On Linux, set the proxy in daemon.json, with internal hosts in no-proxy, and restart the daemon. On Docker Desktop, use Settings, Resources, Proxies.
{
"proxies": {
"http-proxy": "http://proxy.example.com:3128",
"https-proxy": "http://proxy.example.com:3128",
"no-proxy": "*.test.example.com,.example.org,127.0.0.0/8"
}
}3Verify
Restart the daemon and repeat the request from the container.
sudo systemctl restart dockerConfirmed by docs.docker.com
How do I stop it coming back?
- Set DNS and proxy for the daemon once, not per container.
- Put a connect timeout and a clear error in the Go HTTP client so a network fault names the host.
- Test outbound access with a throwaway container whenever the network changes.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Docker pull or container DNS fails with "server misbehaving"
docker pull fails while a browser on the same machine opens the registry fine
'Server misbehaving' is a Go resolver error: the DNS server answered, but with a reply code that is neither success nor name-not-found.
3 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fixServers
AH00558: Apache in Docker cannot reliably determine its fully qualified domain name
Set the 'ServerName' directive globally to suppress this message
AH00558 is a warning, not a crash.
2 causes, each with a fixServers
Apache in a Docker container logs AH01114 when it proxies to a backend
AH01114: HTTP: failed to make connection to backend: api
Apache's proxy worker could not open a connection to the address in ProxyPass.
5 causes, each with a fix