Docker build: use http cache

2019-07-23 04:51发布

问题:

I have a step in my docker file that installs python requirements:

COPY req.txt /req.txt
RUN pip install -r /req.txt

I change req.txt and add/remove packages to/from it frequently and rebuild the image.

Is there a way for docker to use a http cache for downloaded files?

Please do not advise me to change my docker file to something else.

回答1:

I used to do this by build a second image, for example. You can build a basic image.

FROM python
RUN pip install -r req.txt

and build it with the following command:

docker build -t basic_python .

For now, if you want to build your really image, just simply do it with another docker file:

FROM basic_python
RUN ....
CMD ....


标签: docker