创建一个Dockerfile - docker从每个新构建的零开始 [英] Creating a Dockerfile - docker starts from scratch on each new build
问题描述
如demas所说,如果你只是附加行,被缓存。
但是,如果您的Docker文件中的任何地方都有一行,如
添加。 / some / path
那么Docker会假设该行已经改变,即使只有Dockerfile改变。因此,除了您添加的文件夹中的任何之外,不会缓存该行和其后的任何内容。
您应该可以通过密切关注 docker build
命令的输出来查看是否发生了这种情况。
注意:这样做的结果是,如果你正在构建一个Docker文件,你通常希望尽可能晚的在目录中添加文件。当然,你最终不得不对你的文件做一些事情(像某种构建过程),不幸的是很难缓存。
I am trying to build a dockerfile - iteratively adding lines and testing. My understanding was that docker will cache the lines that have already been built and start from the new lines I had added. The case seems to be that it just builds from scratch each time I call build on my container. Is this normal? If not - what am I doing wrong?
As demas said, if you're simply appending lines, the previous lines will be cached.
However, if anywhere in your Dockerfile you have a line like
ADD . /some/path
then Docker will assume that that line has changed even if it was only the Dockerfile that changed. So that line and anything after it will never be cached, unless nothing in the folder you're adding has changed.
You should be able to see whether this is happening by paying close attention to the output of the docker build
command.
As a side note: a consequence of this is that if you're building a Dockerfile, you generally want to add the files in the directory as late as possible, doing any preparations beforehand. Of course, you will end up having to do things to your files (like some kind of build process) which is unfortunately hard to cache.
这篇关于创建一个Dockerfile - docker从每个新构建的零开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!