Google Container Builder 是否需要 Dockerfile,或者 cloudbuild.yaml 是否应该涵盖所有用例?

Moh*_*han 9 google-cloud-platform google-kubernetes-engine

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

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

Joh*_*uth 7

构建 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']
Run Code Online (Sandbox Code Playgroud)

因此,为了构建最终的容器映像,建议使用docker buildand aDockerfile方法。例如,它可以让您轻松安装依赖包。

cloudbuild.yaml您可以在步骤之前或之后使用来执行其他操作docker build。例如,如果您想创建一个二进制文件而不将 SDK 打包到最终映像中,那么使用cloudbuild.yaml. 或者,如果您想使用gsutil.

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

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