[英]accessing host os file from docker container using python
I want to capture the content of file which is located in the host os (linus) into a variable from the Docker container using a python script 我想使用python脚本从Docker容器中将位于主机os(linus)中的文件内容捕获到一个变量中
Can I do this 我可以这样做吗
FILE="/home/test/file.txt"
#open the file for read-only
fd = os.open(FILE,os.O_RDONLY)
content = os.read(fd,12)
print content
ended up with this error 最终出现此错误
OSError: [Errno 2] No such file or directory: '/home/test/file.txt'
Please suggest a way if I am doing it wrong 如果我做错了,请提出一种方法
mount the volume where the file is located into a directory in your docker container 将文件所在的卷挂载到Docker容器的目录中
you do this by using the -v
flag in docker 您可以通过在docker中使用-v
标志来执行此操作
for example: 例如:
docker run -v <HOST_FOLDER>:/data <IMAGE>
that will mount to the folder data
on the root of your container ( /data
) 它将挂载到容器根目录( /data
)上的文件夹data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.