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!

Error installing Zappa on MacOS: “error: could not create /Library/Python/2.7/site-packages/requestlogger”

Attempting to install Zappa on MacOS with:

pip install zappa

I get an error:

error: could not create '/Library/Python/2.7/site-packages/requestlogger': Permission denied

Searching for this error I found similar errors installing other packages, and the recommendation seems to be to use the –home option to install to your home dir. So instead, this worked:

pip install --home zappa