简体   繁体   English

是否可以在 Dockerfile 中制作 FROM 指令来拉取最新的图像?

[英]Is it possible to make a FROM instruction in a Dockerfile pull the most recent image?

I want to know whether it's possible to make a FROM instruction in a Dockerfile pull the most recent image (eg image:latest ) before proceeding with the build?我想知道在继续构建之前是否可以在 Dockerfile 中制作FROM指令来拉取最新的图像(例如image:latest )?

Currently, the image is only pulled if it's not already stored locally.目前,只有在本地还没有存储图像时才会拉取图像。

docker build --pull OTHER_OPTIONS PATH

From https://docs.docker.com/engine/reference/commandline/build/来自https://docs.docker.com/engine/reference/commandline/build/

--pull      Always attempt to pull a newer version of the image

Although there might be genuine use case for this for development pupose, I strongly suggest avoid depending on this option in production builds.尽管出于开发目的可能有真正的用例,但我强烈建议避免在生产版本中依赖此选项。 Docker images must be immutable. Docker 图像必须是不可变的。 Using this option can lead to situations where different images are generated from same source code and any behaviour changes resulting from such builds without corresponding changes in code are hard to debug.使用此选项可能会导致从相同源代码生成不同图像的情况,并且在没有相应代码更改的情况下,此类构建导致的任何行为更改都难以调试。

Say there is a project called "derived project" which uses the base image myBaseImage:latest假设有一个名为“派生项目”的项目使用基础图像myBaseImage:latest

FROM myBaseImage:latest

<snipped>

CMD xyz
docker build --pull -t myDerivedImage:<version of source code> .

Assuming the tag of derived image is based on it's source code version (a git commit hash for example) which is the most common way to tag the images, if a new base image under latest tag is published while there are no changes in derived project, the build of derived project will produce different images under same name before and after the base image change.假设派生图像的标签基于其源代码版本(例如,git 提交 hash)这是标记图像的最常见方法,如果发布了最新标签下的新基础图像而派生项目中没有更改,派生项目的构建会在基础镜像改变前后产生不同的同名镜像。 Once an image is published under a name, it should not be mutated.以名称发布图像后,不应对其进行变异。

In order to build a docker image by updating the base image, you must use the option:为了通过更新基础镜像来构建 docker 镜像,您必须使用以下选项:

--pull

I leave you the official documentation where this option is discussed and many more: official docker documentation我留给您讨论此选项的官方文档以及更多内容:官方 docker 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM