Docker build --no-cache 实际上会下载并刷新基础镜像吗?

2023-11-22

docker build --no-cache 刷新吗updated是否远程基础镜像?文档似乎没有具体说明。


The --no-cache选项将重建图像而不使用本地缓存图层。但是,那FROM如果构建主机上存在已提取的基础映像,该行将重用该基础映像(来自行本身可能不会被缓存,但它提取的图像会被缓存)。如果你想再次拉取基础镜像,你可以使用--pull构建命令的选项。例如。

$ docker build --no-cache --pull -t new-image-name:latest .

要查看构建命令采用的所有选项,您可以运行

$ docker build --help

或查看文档https://docs.docker.com/engine/reference/commandline/build/


以下是您如何自行测试此行为的示例:

$ # very simple Dockerfile
$ cat df.test
FROM busybox:latest
RUN echo hello >test.txt

$ # pull an older version of busybox
$ docker pull busybox:1.29.2
1.29.2: Pulling from library/busybox
8c5a7da1afbc: Pull complete
Digest: sha256:cb63aa0641a885f54de20f61d152187419e8f6b159ed11a251a09d115fdff9bd
Status: Downloaded newer image for busybox:1.29.2

$ # retag that locally as latest
$ docker tag busybox:1.29.2 busybox:latest

$ # run the build, note the image id at the end of each build step
$ DOCKER_BUILDKIT=0 docker build --no-cache -f df.test .
Sending build context to Docker daemon  23.04kB
Step 1/2 : FROM busybox:latest
 ---> e1ddd7948a1c
Step 2/2 : RUN echo hello >test.txt
 ---> Running in dba83fef49f9
Removing intermediate container dba83fef49f9
 ---> 1f824ff05612
Successfully built 1f824ff05612

$ # rerun the build, note step 1 keeps the same id and never pulled a new latest
$ DOCKER_BUILDKIT=0 docker build --no-cache -f df.test .
Sending build context to Docker daemon  23.04kB
Step 1/2 : FROM busybox:latest
 ---> e1ddd7948a1c
Step 2/2 : RUN echo hello >test.txt
 ---> Running in 73df884b0f48
Removing intermediate container 73df884b0f48
 ---> e5870de6c24f
Successfully built e5870de6c24f

$ # run with --pull and see docker update the latest image, new container id from step 1
$ DOCKER_BUILDKIT=0 docker build --no-cache --pull -f df.test .
Sending build context to Docker daemon  23.04kB
Step 1/2 : FROM busybox:latest
latest: Pulling from library/busybox
Digest: sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812
Status: Downloaded newer image for busybox:latest
 ---> 59788edf1f3e
Step 2/2 : RUN echo hello >test.txt
 ---> Running in 7204116ecbf4
Removing intermediate container 7204116ecbf4
 ---> 2c6d8c48661b
Successfully built 2c6d8c48661b

$ # one last run now that busybox:latest is updated shows the pull has nothing to do
$ DOCKER_BUILDKIT=0 docker build --no-cache --pull -f df.test .
Sending build context to Docker daemon  23.04kB
Step 1/2 : FROM busybox:latest
latest: Pulling from library/busybox
Digest: sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812
Status: Image is up to date for busybox:latest
 ---> 59788edf1f3e
Step 2/2 : RUN echo hello >test.txt
 ---> Running in f37e19024e99
Removing intermediate container f37e19024e99
 ---> 044a5d4011c4
Successfully built 044a5d4011c4
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Docker build --no-cache 实际上会下载并刷新基础镜像吗? 的相关文章

随机推荐

  • Outlook 回复或回复全部电子邮件

    Set objOutlook CreateObject Outlook Application Set objMail objOutlook CreateItem 0 objMail To email protected objMail c
  • 如何使参数推导适用于使用基类构造函数的派生类?

    当派生类使用基类构造函数时 推论似乎总是fail 然而 当基类有很多构造函数时 重新定义所有构造函数是非常笨拙的 当基类快速演变为新的构造函数时 这也是一个痛苦 老问题是两年多前提出的 所以我想知道 在 2020 年 c 17 和 c 2a
  • qDebug Qt 控制台应用程序输出到 Qt Creator 应用程序输出

    如何在 Qt 控制台应用程序中使用 qDebug 输出到 Qt Creator 应用程序输出 窗口 当前 qDebug 写入控制台窗口 这会干扰非调试输出 默认情况下 在 Qt GUI 应用程序中使用 qDebug 会输出到应用程序输出窗口
  • 在 ARKit 中获取设备绕世界原点 y 轴的旋转

    当我在 ARKit 中绕 y 轴旋转设备时 我试图计算设备的旋转 为了澄清起见 ARKit 中的 y 轴是垂直于地面指向上方的轴 我使用 eulerangles 来获得相机的旋转 如下所示 var alpha sceneView point
  • Entity Framework 4.1 Codefirst:删除一对多子项时出现“给定多重约束”错误

    我有以下课程实体框架4 1 这些类已被修剪以保持代码的可读性 public class MetaInformation public int Id get set public virtual MetaInformationObject R
  • 存储/检索数据结构

    我已经实施了一个后缀树在Python中进行全文搜索 而且效果非常好 但有一个问题 索引文本可能非常大 因此我们无法在 RAM 中拥有整个结构 IMAGE 单词的后缀树BANANAS 在我的场景中 想象一棵大 100000 倍的树 因此 经过
  • 线性化深度

    在 OpenGL 中 您可以像这样线性化深度值 float linearize depth float d float zNear float zFar float z n 2 0 d 1 0 return 2 0 zNear zFar z
  • LdapConnection SearchRequest 抛出“超出大小限制”异常

    由于我们需要使用 LDAPS 连接到 LDAP 服务器 因此我们必须使用 LdapConnection 而不是 DirectoryEntry 这是源代码 SearchResponse response using LdapConnectio
  • PHP递归函数删除所有子节点导致stackoverflow

    我的MySQL是这样的 表的名称是category id content parent where is 类别的 id 内容 一些我们不关心的文本 父级 父级的 id 类别 这就是我现在正在尝试的 function remrecurs id
  • 是否可以禁用plotly.py烛台图表上的缩放/平移窗口?

    我正在使用plotly py 创建烛台图 我想要进行水平分割 并将烛台数据放在顶部分割中 将一些数据曲线放在底部分割中 我不需要平移和缩放 并且带有缩放 平移控件的烛台图的下部部分妨碍了我 要禁用缩放和平移 您需要设置 layout xax
  • 如何以编程方式关闭/取消/关闭系统对话框 (Android)

    我有一个可以进行 USSD 调用的应用程序 但在所有 USSD 调用之后 我收到了一个向用户显示结果的对话框 我知道可以关闭此对话框 因为 USSD Checker 应用程序执行此操作 它们从 USSD 获取响应而不显示用户对话框 In t
  • 如何全局设置 System.Text.Json.JsonSerializer 的默认选项?

    而不是这个 JsonSerializerOptions options new JsonSerializerOptions PropertyNamingPolicy JsonNamingPolicy CamelCase etc var so
  • Android Studio 项目已经注册

    我在使用 Android Studio 时遇到了一个大问题 我有一个项目依赖于其他两个项目 如库 我跟着导游将项目导入 Android Studio 时出现与 ActionBarSherlock 有关的问题用于导入外部模块 我打开 项目结构
  • Magento 覆盖控制器

    我想做以上的事情 我过去重写过许多文件 块 模型 助手 但这个让我困惑 谁能看到我在这里做错了什么 我已经编辑了这段代码 现在包含一些建议 这是我的文件夹结构 2 个控制器位置作为测试 Idigital Idgeneral etc conf
  • 使用 Rails 3 中的表单按钮覆盖 respond_to 格式

    我有一组使用 Rails 调用 respond to 以各种格式显示的报告 这样如果 URL 以 CSV 或 JSON 结尾 则报告将以该格式生成 我请求制作一个下载按钮 以便更轻松地获取报告 但由于报告具有日期范围等自定义功能 因此我需要
  • Firebase 时间戳至今的日期和时间

    我正在使用 firebase 作为我的聊天应用程序 在聊天对象中 我使用添加时间戳Firebase ServerValue TIMESTAMP method 我需要使用此时间戳在我的聊天应用程序中显示消息接收时间 如果是当前时间 我只需要显
  • Android ActionBarSherlock 顶部栏

    我想要一个像 foursquare 这样的操作栏 我想要的是诸如朋友 探索和我 另外 在选项卡上方 我想要一个自定义布局 其中包括一些按钮 例如foursquare 徽标 刷新和签入在四方 我创建了选项卡 但无法更改 ActionBarSh
  • UILocalNotification 的警报操作代码

    UILocalNotification notif cls alloc init notif fireDate self datePicker date notif timeZone NSTimeZone defaultTimeZone n
  • Java 忽略类路径

    我正在编写一个使用 Oracle JDBC 驱动程序的 java 程序 我已将其设置在我的类路径中 当我在 IDE 中运行程序 作为 jdbc 添加为库 时 程序运行良好 当我尝试部署它时 它完全忽略类路径中的列表并给我一个 NoClass
  • Docker build --no-cache 实际上会下载并刷新基础镜像吗?

    docker build no cache 刷新吗updated是否远程基础镜像 文档似乎没有具体说明 The no cache选项将重建图像而不使用本地缓存图层 但是 那FROM如果构建主机上存在已提取的基础映像 该行将重用该基础映像 来