docker - 如何有条件地拉取 Docker 镜像的最新标签,而不是使用缓存版本?
问题描述
我的 Dockerfile 包含这一行:
COPY --from=whatwg/wattsi:latest /whatwg/wattsi/bin/wattsi /bin/wattsi
whatwg/wattsi
即,它正在从Docker Hub 上可用的映像中复制可执行文件。这基本上直接来自多阶段构建的文档。
但是,一旦我运行 Dockerfile,它就会缓存whatwg/wattsi:latest
. 然后,任何whatwg/wattsi
被推送到 Docker Hub 的后续更新都将被忽略,并使用缓存的副本。(即,这整行被跳过,它创建的层被重用。)
我想要的行为是让 Docker 将远程whatwg/wattsi:latest
与本地缓存副本进行比较,如果有差异则重新下载。那可能吗?
我想在不将版本硬编码到我的 Dockerfile 的情况下做到这一点,每次revswhatwg/wattsi
都需要更新该版本。whatwg/wattsi
解决方案
无法在 dockerfile 中编写它。
但是你可以运行
docker build --pull
从文档
--pull
始终尝试拉取更新版本的映像 https://docs.docker.com/engine/reference/commandline/build/#options
和跑步一样
docker pull whatwg/wattsi:latest
在你的docker build
. 它只是检查您的本地映像副本是否是最新的,如果不是,则拉取较新的版本。
这个问题不仅存在于构建,而且存在于运行它们。Kubernetes 通过imagePullPolicy
. (见https://kubernetes.io/docs/concepts/containers/images/#updating-images)
推荐阅读
- ionic-framework - Angular CDK 虚拟滚动问题
- flutter - 如何在两个平台上都可以使用的支付网关
- c++ - Boost 1.74.0 Asio 执行器迁移问题
- c++ - 开关盒仅打印默认值
- android - 在新的控制台设计中,无法创建生产版本,也无法将 alpha 升级为生产版本
- pycharm - Pycharm:如何在根目录下更改和保存文件?
- sql - 如何解决“没有为'r'的第1列指定列”
- python - 只能使用{}而不是传入python?
- jena - 如何将 Jena 结果集加载到 Jena 模型
- css - 我正在尝试为 href="" 和使用 css的内容自动使用(几乎)相同的文本