代码之家  ›  专栏  ›  技术社区  ›  Varunkumar Manohar

带有gcloud命令的容器生成器dockerfile

  •  0
  • Varunkumar Manohar  · 技术社区  · 7 年前

    我有一个容器构建步骤

    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
    

    当我使用

    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构建步骤中运行?

    2 回复  |  直到 7 年前
        1
  •  0
  •   Alioua    7 年前

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

    在这里面 GitHub 有一个使用gcloud命令的云构建程序示例:

    注意:您必须指定$project_id这是您的生成器必须工作的。

        2
  •  0
  •   David Bendory    7 年前

    做这个,你的 Dockerfile 或者需要从已经安装了cloud sdk的基本映像开始(比如 FROM gcr.io/cloud-builders/gcloud )或者你需要安装它。这是一个 停靠文件 安装它: https://github.com/GoogleCloudPlatform/cloud-builders/blob/master/gcloud/Dockerfile.slim