Docker build is not using cache

风格不统一 提交于 2020-01-22 05:19:10

问题


docker build is not using it's cache.

docker build -f Dockerfile .

generates the same output that this does:

docker build -f Dockerfile --no-cache .

I am modifying the Dockerfile, adding commands at the end of the file. So the previous layers should be cached and valid.

I've got plenty of disk space.

Any ideas?

Docker version 17.06.1-ce, build 874a737

Dockerfile:

FROM registry:5000/base/python:xenial

RUN mkdir /code
COPY . /code

RUN apt-get update && \
    apt-get install -y \
    vim \
    less

COPY /etc/foo /etc/foo

ENTRYPOINT ["/bin/bash"]

回答1:


From your Dockerfile, if you append lines to your Dockerfile, or change the code being built, there's only one line that could be cached:

RUN mkdir /code

After that, you perform a:

COPY . /code

Since you have changed your Dockerfile, the contents of . have changed (the Dockerfile is part of .) and therefore the COPY needs to be performed again, generating a new layer. Once you generate a new layer, every following layer no longer has a cache and needs to be rebuild.

To improve caching, consider placing the lines that change less towards the top of your Dockerfile. That would leave the COPY . /code line at the very end of the file since it will change almost every time.



来源:https://stackoverflow.com/questions/45929081/docker-build-is-not-using-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!