![](/img/trans.png)
[英]debug python code running in docker container from host using vscode
[英]accessing host os file from docker container using python
我想使用python腳本從Docker容器中將位於主機os(linus)中的文件內容捕獲到一個變量中
我可以這樣做嗎
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
最終出現此錯誤
OSError: [Errno 2] No such file or directory: '/home/test/file.txt'
如果我做錯了,請提出一種方法
將文件所在的卷掛載到Docker容器的目錄中
您可以通過在docker中使用-v
標志來執行此操作
例如:
docker run -v <HOST_FOLDER>:/data <IMAGE>
它將掛載到容器根目錄( /data
)上的文件夾data
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.