2

I am building a dockerfile with the docker build . command. While building, I am experiencing the following error:

Downloading/unpacking requests
   Cannot fetch index base URL http://pypi.python.org/simple/
   Could not find any downloads that satisfy the requirement requests
   No distributions at all found for requests

Here is the dockerfile:

FROM jonasbonno/rpi-grovepi
RUN pip install requests
RUN git clone https://github.com/keyban/fogservice.git #update
ENTRYPOINT ["python"]
CMD ["fogservice/service.py"]

What might be the problem?

Kévin Bibollet
  • 3,573
  • 1
  • 15
  • 33
keroth
  • 45
  • 1
  • 6

2 Answers2

2

You have a pip problem, not a docker problem, you need to add pip install --index-url https://pypi.python.org/simple/ --upgrade pip to your docker file:

FROM jonasbonno/rpi-grovepi
RUN pip install --index-url https://pypi.python.org/simple/ --upgrade pip
RUN hash -r
RUN pip install requests
RUN git clone https://github.com/keyban/fogservice.git #update
ENTRYPOINT ["python"]
CMD ["fogservice/service.py"]

You can find the solution here: pip connection failure: cannot fetch index base URL http://pypi.python.org/simple/

  • 2
    There is a typo in your first code line: missing the 'p' in _p_ip. Since it is a single char change, I cannot edit it myself. – Zeitounator May 13 '19 at 09:53
  • In Python 2.7, when trying to update in the Dockerfile or in the container, you get `Cannot fetch index base URL https://pypi.python.org/simple/ Could not find any downloads that satisfy the requirement pip in /usr/lib/python2.7/dist-packages Downloading/unpacking pip Cleaning up... No distributions at all found for pip in /usr/lib/python2.7/dist-packages Storing debug log for failure in /root/.pip/pip.log`. See also the two comments at the end of [pip connection failure: cannot fetch index base URL http://pypi.python.org/simple/](https://stackoverflow.com/a/46963820/11154841) – questionto42 Nov 24 '22 at 14:49
  • Found it out and put it in [another answer](https://stackoverflow.com/a/74563036/11154841), you need to take a younger base image in the Dockerfile. – questionto42 Nov 27 '22 at 06:22
0

Legacy problem

In Python 2.7, a pip installer of Pylons threw the same error. I then read somewhere that upgrading pip could help, and doing so in the bash of the container, you get the same error again, now for pip itself:

Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement pip in /usr/lib/python2.7/dist-packages
Downloading/unpacking pip
Cleaning up...
No distributions at all found for pip in /usr/lib/python2.7/dist-packages
Storing debug log for failure in /root/.pip/pip.log

And when you try upgrading pip in the Dockerfile, you get the same output, but at the end:

The command '/bin/sh -c pip install --index-url https://pypi.python.org/simple/ --upgrade pip' returned a non-zero code: 1

See also the two comments at the end of pip connection failure: cannot fetch index base URL http://pypi.python.org/simple/

The error is thrown only from within your container / when building the image, while in your workspace, you can install the upgrade or the packages. The container's pip does not have the rights to download from the internet since the TLS security changed.

Answer 1: load from your own pip server

I saw a fix in a legacy docker setup, likely for the same reason as in the question. This is not for sure, though, I have not done it myself:

Download the pip installers of the packages you need in your workspace, then upload these pip installers to a local server with your own certificate, and then add that server website with your own setup to a python setup.py file by means of from setuptools import setup, find_packages, then calling the built-in setup(...) function, to pip install the needed packages.

In short: Do not upgrade the pip installer for this, instead, just have the needed tarballs on your own server to get them without TLS problems, and take the setuptools module in a python file for this.

Answer 2: take a younger ubuntu base image in the Dockerfile (recommended)

In a legacy project, for example written in Python 2, try changing the base image, and perhaps even the Python version. I changed the line from FROM ubuntu:14.04 to 15.04, 16.04, and then 18.04. Then I tried pip install Pylons and all of the other needed packages in the bash of the container, but that only worked after

RUN python -m pip install --upgrade pip

(In my project, I could not get the docker containers to run without this, although I vaguely remember that you should not need to upgrade pip if you take the right image from the start; not sure about this, though, perhaps that was only aiming at updated, not upgrade.)

When all of the versions were clear and the app worked, I added the pip installations to a requirements file that gets loaded in the Dockerfile.

questionto42
  • 7,175
  • 4
  • 57
  • 90