【问题标题】:cloud build not able to find the DockerFile云构建无法找到 DockerFile
【发布时间】:2019-10-29 13:05:19
【问题描述】:

我正在尝试使用谷歌云构建触发器构建我的 docker 容器。不幸的是,构建没有找到我的 docker 文件。它不在我的存储库的根目录,但我认为我可以指定一个相对路径。显然我配置错误。下面是我的 cloudbuild.yaml 和输出日志。

如果重要的话 - 我的代码在 github 中,但我将触发器配置为从该 repo 中提取。

steps:
- name: 'gcr.io/cloud-builders/docker'
  args:
  - 'build'
  - '--tag=gcr.io/$PROJECT_ID/domain-session-test:$TAG_NAME'
  - '--file=session_server/deployments/DockerFiles/minimal.Dockerfile'
  - '.'
- name: 'gcr.io/cloud-builders/docker'
  args: ['run', 'gcr.io/$PROJECT_ID/domain-session-test:$TAG_NAME', 'go', 'test']
- name: 'gcr.io/cloud-builders/gsutil'
  args: ['cp', '-r', 'k8s/*', 'gs://$PROJECT_ID-kubernetes-manifests']
images: ['gcr.io/$PROJECT_ID/domain-session-test:$TAG_NAME']

日志:

starting build "1c4ee154-2c29-4e81-b884-d64c54841d71"    
    FETCHSOURCE
    Initialized empty Git repository in /workspace/.git/
    From https://source.developers.google.com/p/MYURL
    * branch c2d8260a49d9972d1b0882c1676184be35b4c33c -> FETCH_HEAD
    HEAD is now at c2d8260 triggering a build
    BUILD
    Starting Step #0
    Step #0: Already have image (with digest): gcr.io/cloud-builders/docker
    Step #0: unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory
    Finished Step #0
    ERROR
    ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1

【问题讨论】:

标签: dockerfile google-cloud-build


【解决方案1】:

我在为 Docker 上下文使用 . 时遇到了类似的情况。

我收到了这个错误...

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /workspace/Dockerfile: no such file or directory

...当使用类似于此的 cloudbuild.yaml 时:

steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/[PROJECT_ID]/[IMAGE]', '.']
# Push the image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
  args: ['push', 'gcr.io/[PROJECT_ID]/[IMAGE]']
# Deploy image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
  args:
  - 'run'
  - 'deploy'
  - '[SERVICE_NAME]'
  - '--image'
  - 'gcr.io/[PROJECT_ID]/[IMAGE]'
  - '--region'
  - '[REGION]'
  - '--platform'
  - 'managed'
images:
- gcr.io/[PROJECT_ID]/[IMAGE]

问题是我的 cloudbuild.yaml 假设工作目录与包含 cloudbuild.yaml 和 Dockerfile 的目录相同。

虽然我的 Cloud Build Trigger 定义知道在哪里可以找到 cloudbuild.yaml 文件,但它显然使用存储库根目录中的工作目录执行该文件,并且存储库的根目录不包含 Dockerfile。

如果我使用类似于以下的构建步骤,问题就解决了。

# Build the container image
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/[PROJECT_ID]/[IMAGE]', '<DIR_CONTAINING_DOCKERFILE>']

【讨论】:

  • 你好 derekbaker... 很高兴我找到了你的帖子,因为我已经坚持了一段时间。但是,我想知道如果我使用例如名为 Dockerfile_abcde 的 dockerfile 它将如何工作。我正在尝试使用以下命令 - 名称:gcr.io/cloud-builders/docker args: [ 'build' , '--tag=gcr.io/$PROJECT_ID/$_IMAGE_NAME' , '--file=Dockerfile_pipeline' , './dataflow/pipeline/' ] 但它似乎不起作用。我的项目在这里github.com/mmistroni/GCP_Experiments/tree/master/dataflow/…感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 2018-04-06
  • 2017-12-04
  • 2019-10-19
  • 2023-01-26
  • 1970-01-01
  • 1970-01-01
  • 2021-01-22
  • 1970-01-01
相关资源
最近更新 更多