2

I try to build a docker image with pip RUN pip3 install *package* --index-url=*url* --trusted-host=*url*. However, it fails with the following error:

Could not find a version that satisfies the requirement *package* (from versions: ) No matching distribution found for *package*.

However, after I removed the package and successfully build the image, I could successfully install the package from docker container!

The bash I used to build image is: sudo docker build --network=host -t adelai:deploy . -f bernard.Dockerfile.

Tengerye
  • 1,796
  • 1
  • 23
  • 46

2 Answers2

1

Please try

docker run --rm -ti python bash

Then run your pip ... inside this container.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
  • Thank you for your kind reply. It is working again. Both the package and base image are created by my company. Is there any clue of what might be the cause please? – Tengerye Jun 08 '20 at 12:30
1

The problem is solved: I set the environment variable during build (ARG http_proxy="*url*") and unset it (ENV http_proxy=) just before the installation.

I am not an expert in docker, but guess the reason is that the environment variables are discarded after the build, which cause the environments are different between dockerfile and docker container.

@Matthias Reissner gives a solid guide, but this answer absolutely provide a more detailed way to debug problems during docker building.

Tengerye
  • 1,796
  • 1
  • 23
  • 46