Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A Go service in a container cannot reach the internet and reports i/o timeout

Errordial tcp: i/o timeout

Short 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.

  • Applies to Go 1.24, Docker Engine 28
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.conf
  2. 2Match what you see, then jump to its fix

    1. 1The lookup fails or times out inside the container but works on the hostThe container's DNS servers are wrong or unreachableFix
    2. 2Lookups work, but connections to outside hosts time out only on the company networkOutbound traffic must go through a proxy the daemon does not useFix

What does the error look like?

  • dial tcp: i/o timeout
  • the 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.conf

2Fix

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-app

3Verify

Start the service with the same flags; the call that timed out now succeeds.

docker run --rm --dns 1.1.1.1 my-go-app

Confirmed by docs.docker.com

Did this fix it?

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.json

2Fix

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 docker

Confirmed by docs.docker.com

Did this fix it?

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.