[英]How to make the docker container search the file within the host rather than within the container?
我有一個python 腳本,它從用戶處理該文件中獲取輸入文件路徑,並在用戶在終端中指定的位置提供輸出文件。 下面是我的代碼,它采用文件路徑。
inputfilepath = input("Enter the input file path")
print(inputfilepath)
outputfilepath = input("Enter the output file path")
print(outputfilepath)
inputPath = inputfilepath
如果我在 Pycharm 中運行這個 python 代碼,它工作正常,但是如果我創建一個相同代碼的 docker 圖像並輸入輸入文件路徑,它會給出“找不到文件錯誤”。
和
因為如果我給出主機/本地機器的文件路徑,它會在容器的工作目錄中而不是在本地機器中搜索該路徑。
如何讓容器搜索本地文件系統上的文件路徑? 提前致謝!
您應該將文件(或包含文件的目錄)從主機掛載到容器。
假設您希望容器中的路徑與主機中的路徑相同:
docker run \
--mount type=bind,source=/path/to/directory,target=/path/to/directory
請參閱有關綁定安裝的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.