All Articles
Tech

Docker: Failed to establish a new connection: [Errno 113] No route to host

Experienced a strange issue today while rebuilding one of my Python containers which was failing on pip install.

The problem is strange because internet works fine on my host system (that also uses Google's 8.8.8.8). Seems to be a temporary issue, possibly because of a DNS change on part of the python module registry pythonhosted.org, but I can't be sure.

 ---> fc2678812fdf
Step 9/11 : RUN python -m pip install --no-cache-dir -r requirements.txt  
 ---> Running in 50711357a3eb
Collecting aiohttp (from -r requirements.txt (line 1))  
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fce4cec2898>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/09/7f/95e1f38eb778c76b1d5f008efc9f3d648dadd22275497a038ee0844dcd62/aiohttp-3.1.3-cp36-cp36m-manylinux1_x86_64.whl
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fce4cec2be0>: Failed to establish a new connection: [Errno 113] No route to host',)': /packages/09/7f/95e1f38eb778c76b1d5f008efc9f3d648dadd22275497a038ee0844dcd62/aiohttp-3.1.3-cp36-cp36m-manylinux1_x86_64.whl
...
Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/09/7f/95e1f38eb778c76b1d5f008efc9f3d648dadd22275497a038ee0844dcd62/aiohttp-3.1.3-cp36-cp36m-manylinux1_x86_64.whl (Caused by NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fce4cebc400>: Failed to establish a new connection: [Errno 113] No route to host',))  

Solution

Switching to another DNS service fixes the issue.

  1. [sudo] vi /etc/docker/daemon.json
  2. Set the DNS resolvers to something new "dns": ["1.0.0.1", "8.8.8.8", "8.8.4.4"]
    I added 1.0.0.1 which is Cloudflare's new DNS service.
  3. Restart the docker daemon: [sudo] systemctl restart docker
  4. Rebuild your container