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
.
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.