Docker构建未使用缓存 [英] Docker build is not using cache
问题描述
docker build
没有使用其缓存。
docker build -f Dockerfile .
生成的输出与此相同:
docker build -f Dockerfile --no-cache .
我正在修改Dockerfile,在文件末尾添加命令。因此,前面的层应该被缓存并且有效。
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.
有什么想法吗?
Docker版本17.06.1-ce,内部版本874a737
Docker version 17.06.1-ce, build 874a737
Dockerfile:
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"]
推荐答案
从您的Dockerfile,如果将行添加到Dockerfile,或更改正在构建的代码,则只能缓存一行:
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
在那之后,您执行:
COPY . /code
由于更改了Dockerfile,所以的内容。
已更改(Dockerfile是。
的一部分),因此需要再次执行 COPY
,生成一个新层。生成新层后,接下来的每一层将不再具有缓存,需要重新构建。
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.
要改善缓存,请考虑将变化不大的行放在顶部您的Dockerfile。这将离开 COPY。 / code
文件末尾的行,因为它几乎每次都会更改。
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.
这篇关于Docker构建未使用缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!