2
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
error404
  • 2,684
  • 2
  • 13
  • 21
user8024713
  • 61
  • 1
  • 5
  • You should format the question properly so that it is readable and looks neat and is understandable, may be also provide brief background etc. You may use preview option before submitting. This will help you get best solutions/answers from the community and may be some upvotes too! – rajesh-nitc Mar 26 '19 at 07:28
  • Hi, Please describe the problem, what you have done and use code formatting in order to get more attention to your question. – Veerendra K Mar 26 '19 at 07:29
  • /workspace directory exists on the local server ? – error404 Mar 26 '19 at 07:58
  • /workspace does not exist on local server , it exists on the pod . @error404 – user8024713 Mar 26 '19 at 08:11

3 Answers3

2

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
  • 55,923
  • 34
  • 110
  • 156
1

hi i just solved this problem.

my node name: m1.env.lab.io

my Dockerfile path: /root/kaniko/demo1/Dockerfile

FROM ubuntu
ENTRYPOINT ["/bin/bash", "-c", "echo hello"]

pod.yaml in /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
katy
  • 11
  • 2
0

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?.

Mark
  • 3,644
  • 6
  • 23