无法从运行在kubernetes pod中的docker写入文件 [英] Unable to write file from docker run inside a kubernetes pod
问题描述
我有一个使用卷写入文件的docker映像:
I have a docker image that uses a volume to write files:
docker run --rm -v /home/dir:/out/ image:cli args
当我尝试在Pod内运行此程序时,容器正常退出,但未写入任何文件.
when I try to run this inside a pod the container exit normally but no file is written.
我不明白.
如果找不到卷,则容器抛出错误,例如,如果我在没有-v
选项的情况下运行它,则会抛出错误:
The container throw errors if it does not find the volume, for example if I run it without the -v
option it throws:
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/out/file.txt'.
但是容器没有任何错误. 就像写文件一样完成,但是文件不存在.
But I don't have any error from the container. It finishes like it wrote files, but files do not exist.
我对Kubernetes还是很陌生,但这让我发疯了.
I'm quite new to Kubernetes but this is getting me crazy.
Kubernetes是否会阻止文件写入?还是我缺少明显的东西?
Does kubernetes prevent files from being written? or am I missing something obvious?
如果有帮助,整个Kubernetes上下文将由GCP composer-airflow管理...
The whole Kubernetes context is managed by GCP composer-airflow, if it helps...
docker -v: Docker version 17.03.2-ce, build f5ec1e2
推荐答案
If you want to have that behavior in Kubernetes you can use a hostPath
volume.
基本上,您可以在Pod规范中指定它,然后将卷安装在Pod运行的节点上,然后在Pod退出后该文件应该位于该节点中.
Essentially you specify it in your pod spec and then the volume is mounted on the node where your pod runs and then the file should be there in the node after the pod exits.
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: image:cli
name: test-container
volumeMounts:
- mountPath: /home/dir
name: test-volume
volumes:
- name: test-volume
hostPath:
path: /out
type: Directory
这篇关于无法从运行在kubernetes pod中的docker写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!