I'm following the fig guide to using docker with a python application, but when docker gets up to the command
RUN pip install -r requirements.txt
I get the following error message:
Step 3 : RUN pip install -r requirements.txt ---> Running in fe0b84217ad1 Collecting blinker==1.3 (from -r requirements.txt (line 1)) Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', gaierror(-2, 'Name or service not known'))': /simple/blinker/
This repeats several times and then I get another message:
Could not find any downloads that satisfy the requirement blinker==1.3 (from -r requirements.txt (line 1)) No distributions at all found for blinker==1.3 (from -r requirements.txt (line 1))
So for some reason pip can't access any packages from inside a docker container. Is there anything I need to do to allow it internet access?
However pip works fine to install things outside of the docker container, and worked fine even with that exact package (blinker==1.3
) so that's not the problem. Also this problem isn't specific to that package. I get the same issue with any pip install
command for any package.
Does anyone have any idea what's going on here?
Method 1: Using Command Line InterfaceTo install any packages, you first need to update the OS. Step 3: After you have updated the Docker Container, you can now install the Firefox and Vim packages inside it. You can now easily use these packages through the bash itself.
The python-pip package manager works as an independent package manager on Linux distribution. This means you need to install the pip tool separately from python programs. The pip command is not found an error raised on your Linux terminal window if the pip is not installed independently on Ubuntu 20.04 system.
You can use it to install and manage Python software packages. In this article, learn how to install pip on Ubuntu 18.04. Note: If you are using Python in a virtual environment created with pyvenv or virtualenv, then pip is available regardless of the version of Python in use. This also applies to Python 2.7.
Your problem comes from the fact that Docker is not using the proper DNS server. You can fix it in three different ways :
Modifying /etc/resolv.conf and adding the following lines at the end
# Google IPv4 nameservers nameserver 8.8.8.8 nameserver 8.8.4.4
If you want to add other DNS servers, have a look here.
However this change won't be permanent (see this thread). To make it permanent : $ sudo nano /etc/dhcp/dhclient.conf
Uncomment and edit the line with prepend domain-name-server : prepend domain-name-servers 8.8.8.8, 8.8.4.4;
Restart dhclient : $ sudo dhclient
.
As explained in the docs :
Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use 127.0.0.1 as the default nameserver in /etc/resolv.conf file.
To specify a DNS server for use by Docker :
1. Log into Ubuntu as a user with sudo privileges. 2. Open the /etc/default/docker file for editing : $ sudo nano /etc/default/docker 3. Add the following setting for Docker. DOCKER_OPTS="--dns 8.8.8.8" 4. Save and close the file. 5. Restart the Docker daemon : $ sudo systemctl restart docker
When you run docker, simply add the following parameter : --dns 8.8.8.8
I needed to add --network=host to my docker build command:
docker build --network=host -t image_name .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With