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
使用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 -Path到要构建的dockerfile。 (默认“Dockerfile”) --context string -Path到dockerfile构建上下文。 (默认“/ workspace /”)
即使这一个陈述有效:
args: ["--destination=gcr.io/kubernetsjenkins/jenkinsondoc:latest"]
希望这有帮助。你能测试一下并与结果分享吗?
文件夹看起来像
在主持人:
/home/sabadsulla/kanikodir/Dockerfile
当它转向PV / PVC时,在容器中
/workspace/Dockerfile
那么对于kanino executor
,如果我们将上下文映射到workspace
,则dockerfile将与上下文相关联是Dockerfile
,所以
--context=/workspace
--dockerfile=Dockerfile