如何在从repo安装pip时使Dockerfile缓存无效



我有一个Dockerfile,需要从私有git repo安装最新的包代码,但由于Dockerfile/url/commit没有更改(我只是遵循master中的最新版本(,Docker会缓存此请求,不会提取最新的代码。

我可以完全禁用构建缓存,这可以解决问题,但这会导致构建缓慢。

我怎么能强迫docker不使用一个命令的缓存?

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7
COPY ./requirements.txt /app
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
# This needs to be separate to trigger to invalidate the build cache
RUN pip install -e git+https://TOKEN@github.com/user/private-package.git#egg=private_package
COPY ./main.py /app
COPY ./app /app/app

添加

ARG foo=bar

在docker文件中的RUN pip install -e ...之前。然后在脚本中添加docker build ....作为参数--build-arg foo="$(date -s)"

最新更新