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

3/26/2019
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

I am running kaniko on a kubernetes pod to build a docker image and pushing to the GCR.

When i use google cloud storage for the CONTEXT_PATH it works fine , But i need to use the Local_directory(meaning using the shared volumes of the pods) AS the CONTEXT_PATH it throws an error

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

Usage:

I tried with args "--context=/workspace" , "--context=dir://workspace" , it gives the same error
-- user8024713
docker
google-cloud-platform
kaniko
kubernetes

2 Answers

4/26/2019

the folder looks like

In host:

/home/sabadsulla/kanikodir/Dockerfile

When it turns to PV/PVC, in pod container

/workspace/Dockerfile

Then for kanino executor, if we map the context to workspace, the dockerfile will be related to context is Dockerfile, so

--context=/workspace
--dockerfile=Dockerfile
-- Larry Cai
Source: StackOverflow

3/31/2019

using kaniko container and volume mounted as persistent volume claim.
Please try and use"--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/

Using the default values:
--dockerfile string -Path to the dockerfile to be built. (default "Dockerfile")
--context string -Path to the dockerfile build context. (default "/workspace/")

Even this one statement works:
args: ["--destination=gcr.io/kubernetsjenkins/jenkinsondoc:latest"]
Hope this help. Could you please test it and share with the results?.

-- Hanx
Source: StackOverflow