gpt4 book ai didi

google-cloud-platform - Google Container Builder 是否需要 Dockerfile 还是 cloudbuild.yaml 应该涵盖所有用例?

转载 作者:行者123 更新时间:2023-12-04 03:12:28 27 4
gpt4 key购买 nike

假设所有容器构建都发生在 Google Container Builder (GCB) 上的工作流程,是否还需要 Dockerfile?

例如,要构建自定义容器,我们希望在其中安装一些包或从本地文件系统复制文件,我看到大多数示例 GCB 仍在使用 Dockerfile(例如 https://github.com/GoogleCloudPlatform/cloud-builders) - 这是因为它无法使用 cloudbuild.yaml 吗?

最佳答案

构建 Docker 容器镜像最简单的工具仍然是使用 docker build带有 Dockerfile 的命令.有一个 cloudbuild.yaml 是很常见的。使用 Dockerfile 的单个步骤的文件在源的根目录中,如下所示:

steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/${PROJECT_ID}/my-image', '.']
images: ['gcr.io/${PROJECT_ID}/my-image']

因此,为了构建最终的容器镜像,使用 docker build和一个 Dockerfile是推荐的方法。例如,它可以让您轻松安装依赖包。

您可以使用您的 cloudbuild.yamldocker build 之前或之后执行其他操作步。例如,如果您想在不将 SDK 打包到最终镜像中的情况下创建二进制文件,使用 cloudbuild.yaml 很容易做到这一点。 .或者,如果您想使用 gsutil 从 Cloud Storage 中提取一些额外的 Assets .

容器构建器还可以让您构建和推送任意数量的镜像,所有镜像都与您的 git 存储库的相同提交相关联(并且它们也可以在镜像标签中包含提交 sha),通过运行多个步骤 docker build .您甚至可以并行运行这些构建。

https://cloud.google.com/container-builder/docs/api/build-steps了解如何为任意事物添加步骤。

关于google-cloud-platform - Google Container Builder 是否需要 Dockerfile 还是 cloudbuild.yaml 应该涵盖所有用例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43959446/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com