【问题标题】:error resolving dockerfile path: please provide a valid path to a Dockerfile within the build context with --dockerfile解析 dockerfile 路径时出错:请使用 --dockerfile 在构建上下文中提供 Dockerfile 的有效路径
【发布时间】:2019-08-16 12:20:27
【问题描述】:
apiVersion: v1
kind: Pod
metadata:
  name: kaniko
spec:
  containers:
  - name: kaniko
    image: gcr.io/kaniko-project/executor:latest
    args:
          - "--context=dir:///workspace"
          - "--dockerfile=/workspace/Dockerfile"
          - "--destination=gcr.io/kubernetsjenkins/jenkinsondoc:latest"
    volumeMounts:
      - name: kaniko-secret
        mountPath: /secret
      - name: context
        mountPath: /workspace
    env:
      - name: GOOGLE_APPLICATION_CREDENTIALS
        value: /secret/kaniko-secret.json
  restartPolicy: Never
  volumes:
    - name: kaniko-secret
      secret:
        secretName: kaniko-secret
    - name: context
      hostPath:
        path: /home/sabadsulla/kanikodir

我在 kubernetes pod 上运行 kaniko 以构建 docker 映像并推送到 GCR。

当我为 CONTEXT_PATH 使用谷歌云存储时,它工作正常, 但我需要使用 Local_directory(意味着使用 pod 的共享卷)作为 CONTEXT_PATH 它会引发错误

"Error: error resolving dockerfile path: please provide a valid path to a Dockerfile within the build context with --dockerfile

用法:

I tried with args "--context=/workspace" , "--context=dir://workspace" , it gives the same error

【问题讨论】:

  • 您应该正确地格式化问题,使其可读,看起来整洁且易于理解,还可以提供简要背景等。您可以在提交前使用预览选项。这将帮助您从社区中获得最佳解决方案/答案,并且可能还会获得一些支持!
  • 你好,请描述问题,你做了什么,并使用代码格式化,以便更多地关注你的问题。
  • /workspace 目录是否存在于本地服务器上?
  • /workspace 在本地服务器上不存在,它存在于 pod 上。 @error404

标签: docker kubernetes google-cloud-platform kaniko


【解决方案1】:

文件夹看起来像

在主机中:

/home/sabadsulla/kanikodir/Dockerfile

当它转向 PV/PVC 时,在 pod 容器中

/workspace/Dockerfile

那么对于kanino executor,如果我们将上下文映射到workspace,那么与上下文相关的dockerfile就是Dockerfile,所以

--context=/workspace
--dockerfile=Dockerfile

【讨论】:

    【解决方案2】:

    使用 kaniko 容器和安装的卷作为持久卷声明。
    请尝试使用"--dockerfile=./Dockerfile"

          containers:
          - name: kaniko
            image: gcr.io/kaniko-project/executor:latest
            args: ["--dockerfile=./Dockerfile",
                   "--context=/workspace/",
                   "--destination=gcr.io/kubernetsjenkins/jenkinsondoc:latest"]
            volumeMounts:
              - name: kaniko-secret
                mountPath: /secret
              - name: context
                mountPath: /workspace/
    

    使用默认值:
    --dockerfile string - 要构建的 dockerfile 的路径。 (默认“Dockerfile”)
    --context string - dockerfile 构建上下文的路径。 (默认为“/workspace/”)

    即使这句话也有效:
    args: ["--destination=gcr.io/kubernetsjenkins/jenkinsondoc:latest"]
    希望这有帮助。你能测试一下并分享结果吗?

    【讨论】:

      【解决方案3】:

      嗨,我刚刚解决了这个问题。

      我的节点名称:m1.env.lab.io

      my Dockerfile path: /root/kaniko/demo1/Dockerfile
      
      FROM ubuntu
      ENTRYPOINT ["/bin/bash", "-c", "echo hello"]
      

      pod.yaml 在 /root/kaniko/demo1/pod.yaml:

      apiVersion: v1
      kind: Pod
      metadata:
        name: kaniko
        namespace: kaniko
      spec:
        nodeName: m1.env.lab.io
        containers:
        - name: kaniko
          image: gcr.io/kaniko-project/executor:latest
          args: ["--verbosity=trace",
                 "--log-format=color",
                 "--dockerfile=Dockerfile",
                 "--context=dir:///workspace/",
                 "--destination=registry.local/cloud2go/kaniko-ubuntu:v0.1"] # no account and password for my registry.
          volumeMounts:
            - name: dockerfile-storage
              mountPath: /workspace/
        restartPolicy: Never
        volumes:
          - name: dockerfile-storage
            hostPath:
               path: /root/kaniko/demo1
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-05
        • 1970-01-01
        • 2019-10-09
        • 1970-01-01
        • 2014-09-25
        相关资源
        最近更新 更多