【问题标题】:Is there any way to "apply a patch" to a docker image?有没有办法给 docker 镜像“应用补丁”?
【发布时间】:2015-03-05 14:54:29
【问题描述】:

有没有办法给 docker 镜像“应用补丁”,尤其是一个或多个 RUNADD 等命令?

例如,RUN 命令可能需要 20 分钟才能运行,它会下载、编译和安装二进制文件。是否可以对此进行比较并将其应用于另一个图像?

我能想到的唯一方法(我还没有尝试过)是运行docker diff,解析输出,创建一个tgz,然后在另一个Dockerfile 中使用tgz 作为ADD

我了解这存在一些问题,例如如果事先调用了apt-get update,这可能会破坏二进制文件的预期动态库链接等。我可以接受,因为我的测试将失败,并表明我必须再次重建“差异”。

我也意识到可能存在冲突。我很乐意完全替换该文件。

此功能的原因是为了节省时间。例如有时需要更改早期的Dockerfile 命令,并且会破坏缓存。此外,尽管我尽量使它们相同以利用缓存,但两个不同 Dockerfile 中的上述命令并不总是相同。

【问题讨论】:

    标签: docker diff patch


    【解决方案1】:

    简短的回答是不,你不能那样做。

    长答案是,如果有足够的动力,您也许能够编写出您想要的代码。我在这里写了一些关于 docker 图像格式的文档(以及用于操作这些图像的工具):

    这可能会给你一些关于从哪里开始的想法。

    就个人而言,我怀疑这种努力是不值得的。

    【讨论】:

      【解决方案2】:

      我知道我们可以使用不同的方法来应用补丁或更新。

      1.Patching using the Dockerfile
      2.Patching an instance of the container and converting it to an image
      

      我按照第二个程序应用任何补丁。这有助于我在构建或推送到 repo 之前测试和更新我的图像。

       1. Create a container from the image you would like to update.
       2. Inside the container, run the native package manager and update the  desired packages or patches.
       3. Exit the container instance.
       4. Commit the changes done to get the updated image.
       5. Stop the containers that were instantiated from the pre-updated image.
       6. Instantiate new containers from the update image.
      

      【讨论】:

        猜你喜欢
        • 2020-10-08
        • 2022-01-18
        • 2012-01-24
        • 2022-12-09
        • 2010-09-14
        • 2018-09-14
        • 2020-07-27
        • 2023-03-30
        • 2023-02-10
        相关资源
        最近更新 更多