getting dial tcp: i/o timeout when accessing internet from a service inside a container

Amit Chahar picture Amit Chahar · Mar 2, 2018 · Viewed 11.3k times · Source

I am using PubNub (GO SDK) publish/subscribe service to receive messages but I am not receiving any messages even when I am able to ping google.com from inside the container.

In the Pubnub logs, every time my program tries to connect to the origin (Pubnub server), I am getting "dial tcp: i/o timeout" error. I guess this is due to the slow internet connection either on the host or in the container.

What should I do to get around this error?

Answer

Amit Chahar picture Amit Chahar · Mar 2, 2018

I was to solve this error by including Google DNS (8.8.8.8) in my machine's nameservers. I think this error was due to the slow domain resolution process as my machine was getting DNS from DHCP.

I followed these steps:

  1. Set static DNS in /etc/resolvconf/resolv.conf.d/basefile:

    nameserver 8.8.8.8
    nameserver 8.8.4.4

  2. Configure your PC so that it uses user-provided DNS, instead of obtaining it from DHCP. For that, open this file /etc/dhcp/dhclient.conf and add this line:

    supersede domain-name-servers 8.8.8.8, 8.8.4.4;

  3. Restart network manager using:

    sudo service network-manager restart