创建一个Dockerfile - docker从每个新构建的零开始 [英] Creating a Dockerfile - docker starts from scratch on each new build

查看:148
本文介绍了创建一个Dockerfile - docker从每个新构建的零开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个dockerfile - 迭代地添加行和测试。我的理解是,docker将缓存已经建立的行,并从我添加的新行开始。这种情况似乎是每次在我的容器上调用build时,它都是从头开始构建的。这是正常吗?如果没有 - 我做错了什么?

解决方案

如demas所说,如果你只是附加行,被缓存。



但是,如果您的Docker文件中的任何地方都有一行,如

 添加。 / some / path 

那么Doc​​ker会假设该行已经改变,即使只有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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆