docker-library / python

Docker Official Image packaging for Python
https://www.python.org/
MIT License
2.5k stars 1.04k forks source link

Inexplicable pip install caching behavior #910

Open maxupp opened 3 months ago

maxupp commented 3 months ago

I have been bashing my head against this for hours. I build my Docker image based on python:3.12, and then install my package like this:

FROM python:3.12

RUN mkdir /build
COPY pyproject.toml /build/pyproject.toml
COPY src /build/src

# set up access token usage
ARG ACCESS_TOKEN=*******************************
RUN git config --global url."https://${ACCESS_TOKEN}@github".insteadOf ssh://git@github

WORKDIR build
RUN pip install --force-reinstall --no-cache-dir .

One of my dependencies in the pyproject.toml is directly from a git repository, with a specified version tag.

dependencies = [ "boto3", "itsdangerous", "jsonref", "pydantic", "python-dotenv", "PyYAML", "typing", "websockets", "*** @ git+ssh://git@github.com/********@v2.2.0" ]

But whatever I do, I can't get pip to install the correct version of the package. I have cleared any cache I can think of, but for some reason I always end up with an old version.

PROBABLE FACTOR: The old version and the tagged version share the same version number within the pyproject.toml, due to an oversight I cannot fix right now. I will bump the version in the near future and I suspect that will make this whole issue go away.

But I really need to know what is happening here, since I'm questioning my sanity.

tianon commented 3 months ago

I'm afraid I'm at a total loss -- you'll possibly have better luck in a dedicated support forum, especially one with deeper PIP experience. :sweat_smile:

The best I can offer is perhaps trying docker build --no-cache which should disable any Docker cache (and your Dockerfile shouldn't have any other cache available unless it's inside src itself)?