【问题标题】:How can I use my "gha" Docker cache to speed up Docker pull, as well as Docker build on Github Actions?如何使用我的“gha”Docker 缓存来加速 Docker 拉取,以及在 Github Actions 上构建 Docker?
【发布时间】:2021-12-09 17:56:46
【问题描述】:

在 Github Actions 上,当我将新构建的 Docker 映像保存在缓存中时,我希望避免从注册表中提取它(这是我工作中最慢的部分)

我的工作流程是这样的

  1. 构建映像(包含我所有的依赖项)
  2. 在上图中运行命令

根据Docker Build Push Action docs,将cache-tocache-from 设置为指向gha 有助于加快第1 步。

但是,当我运行docker run ghcr.io/org/image:new-tag command 时,它总是以

Unable to find image 'ghcr.io/org/image:new-tag' locally
new-tag: Pulling from org/image
...
5402d6c1eb0a: Pulling fs layer
...

大约需要 50 秒(总工作时间约为 75 秒)。

当存在包含此信息的缓存时,这似乎是不必要的,但是我不知道如何告诉我的 docker run 命令如何使用此缓存,据我所知,没有--cache-from=gha docker run 的等效选项。

当我在 Github Actions 上调用 docker run 时,如何告诉 docker 在 gha 缓存中查找图像?

【问题讨论】:

    标签: docker caching continuous-integration github-actions buildx


    【解决方案1】:

    我们前段时间遇到过类似的情况,但我们最近发现了一个 github-actions,它实际上有助于缓存 docker-layers 和图像 b/w 后续运行。

    我相信你的问题也可以用它来解决。这是 gh-action https://github.com/satackey/action-docker-layer-caching 的链接。

    配置示例 您可以在 docker run 步骤上方添加以下行,以确保在 gha 中完成缓存

        - uses: satackey/action-docker-layer-caching@v0.0.11
          continue-on-error: true
    

    【讨论】:

    • 这比我当前的解决方案(从缓存中提取)要慢。好主意。
    【解决方案2】:

    但是,一旦您开始在虚拟机上构建映像,并且每次运行后都会被销毁,您就失去了缓存的所有优势。

    请参阅本教程将对您有所帮助。 https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching

    【讨论】:

      猜你喜欢
      • 2020-01-01
      • 2021-06-05
      • 2021-01-01
      • 2022-11-18
      • 2021-06-07
      • 2023-02-17
      • 2021-06-25
      • 2018-02-06
      • 2018-11-04
      相关资源
      最近更新 更多