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吊舱上运行kaniko,以构建docker映像并推送到GCR。
当我将Google云存储用于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
答案 0 :(得分:0)
使用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字符串-要构建的dockerfile的路径。 (默认为“ Dockerfile”)
--context字符串-dockerfile构建上下文的路径。 (默认为“ / workspace /”)
即使这句话起作用:
args: ["--destination=gcr.io/kubernetsjenkins/jenkinsondoc:latest"]
希望对您有所帮助。您能否对其进行测试并与结果分享?
答案 1 :(得分:0)
文件夹外观
在主持人中:
/home/sabadsulla/kanikodir/Dockerfile
当使用PV / PVC时,请放在豆荚容器中
/workspace/Dockerfile
然后针对kanino executor
,如果我们将上下文映射到workspace
,则dockerfile将与上下文相关Dockerfile
,所以
--context=/workspace
--dockerfile=Dockerfile
答案 2 :(得分:0)
嗨,我刚刚解决了这个问题。
我的节点名称:m1.env.lab.io
my Dockerfile path: /root/kaniko/demo1/Dockerfile
FROM ubuntu
ENTRYPOINT ["/bin/bash", "-c", "echo hello"]
/root/kaniko/demo1/pod.yaml中的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