20

pip install error inside Docker container: Failed to establish a new connection:...

 2 years ago
source link: https://www.kevinhooke.com/2021/05/22/pip-install-error-inside-docker-container-failed-to-establish-a-new-connection-errno-3-temporary-failure-in-name-resolution/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

pip install error inside Docker container: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

Trying to install some Python packages with pip inside a Docker container I ran into this issue:

# pip3 install pytest
Collecting pytest
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7feb52c30630>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pytest/

At first I thought this something to do with network restrictions since I’m running this on a Linux AWS Workspace, but I have internet access enabled. Running the command on the Workspace itself works as expected, so this is something specific to the Docker container. Next I thought this might be something to do with the specific container image I was using, but after trying a few others I had the same error on any container.

Searching for the error “Failed to establish a new connection: [Errno -3] Temporary failure in name resolution” online I found this question and answer, and suggested to run the Docker container with the host networking option.

So instead of running bash in the container like this:

$ docker run -it tensorflow/tensorflow:1.12.0-py3 bash

Pass in the network=host option like this:

$ docker run --network=host -it tensorflow/tensorflow:1.12.0-py3 bash
# pip3 install pytest
Collecting pytest
  Downloading https://files.pythonhosted.org/packages/b1/ee/53945d50284906adb1e613fabf2e1b8b25926e8676854bb25b93564c0ce7/pytest-6.1.2-py3-none-any.whl (272kB)
    100% |################################| 276kB 9.4MB/s 

Problem solved!

CategoriesKev's BlogTagsaws, aws workspace, docker, pip, python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.

Notify me of follow-up comments by email.

Notify me of new posts by email.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post navigation


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK