Docker how to run pip requirements.txt only if there was a change?

前端 未结 3 1017
滥情空心
滥情空心 2020-12-02 05:39

In a Dockerfile I have a layer which installs requirements.txt:

FROM python:2.7
RUN pip install -r requirements.txt

When I bui

3条回答
  •  伪装坚强ぢ
    2020-12-02 06:20

    This is directly mentioned in Docker's own "Best practices for writing Dockerfiles":

    If you have multiple Dockerfile steps that use different files from your context, COPY them individually, rather than all at once. This will ensure that each step’s build cache is only invalidated (forcing the step to be re-run) if the specifically required files change.

    For example:

    COPY requirements.txt /tmp/
    RUN pip install --requirement /tmp/requirements.txt
    COPY . /tmp/
    

    Results in fewer cache invalidations for the RUN step, than if you put the COPY . /tmp/ before it.

提交回复
热议问题