【问题标题】:Container builder dockerfile with gcloud commands带有 gcloud 命令的容器构建器 dockerfile
【发布时间】:2018-07-18 03:59:41
【问题描述】:

我有一个容器构建器步骤

steps:
- id: dockerbuild
  name: gcr.io/cloud-builders/docker
  entrypoint: 'bash'
  args:
  - -c
  - |
    docker build . -t test 
images: ['gcr.io/project/test']

用于创建此测试映像的 Dockerfile 具有 gsutil 特定命令,例如

FROM gcr.io/cloud-builders/gcloud
RUN gsutil ls

当我使用 docker build 向容器构建器服务提交时

gcloud container builds submit --config cloudbuild.yml

我看到以下错误

You are attempting to perform an operation that requires a project id, with none configured. Please re-run gsutil config and make sure to follow the instructions for finding and entering your default project id.
The command '/bin/sh -c gsutil ls' returned a non-zero code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1

我的问题是,我们如何在 DockerFile 中使用 gcloud/gsutil 命令,以便我可以在 docker build 步骤中运行?

【问题讨论】:

标签: google-container-registry google-container-builder


【解决方案1】:

调用“gcloud 命令”。使用工具生成器,您需要 Container Builder service account,因为它代表您执行构建。

GitHub 中有一个使用 gcloud 命令的云构建器示例:

注意:您必须指定 $PROJECT_ID,这是您的构建器工作所必需的。

【讨论】:

    【解决方案2】:

    为此,您的Dockerfile 需要从已安装云 SDK 的基础映像(如FROM gcr.io/cloud-builders/gcloud)开始,或者您需要安装它。这是安装它的Dockerfilehttps://github.com/GoogleCloudPlatform/cloud-builders/blob/master/gcloud/Dockerfile.slim

    【讨论】:

    • 感谢您的回复。我尝试做同样的事情,但是在容器构建器步骤的 dockerfile 中发出 gcloud/gsutil 命令会引发我没有足够权限的错误
    猜你喜欢
    • 1970-01-01
    • 2017-11-21
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    相关资源
    最近更新 更多