python - 如何在Windows的Docker中挂载卷?

标签 python windows docker

我正在尝试将数据从我的Docker应用程序保存到主机文件夹。
我的dockerfile是:

FROM python:3
   
# set a directory for the app
WORKDIR /usr/src/app

# copy all the files to the container
COPY . .

# install dependencies
RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 8050

CMD ["python", "./app.py"]
然后,我构建图像:
docker build <path> -t <tag>
然后运行:
docker run -p 8050:8050 <tag>
为了保存来自docker app的输出,我试图这样做
pd.DataFrame(rows).to_excel('S:/Folder1/Folder2/Folder3/file.xlsx', index=False) 
我必须在Docker设置>资源>文件共享中挂载该卷,我已经添加了目录'S:/Folder1/Folder2/Folder3/',以便可以将其挂载到Docker容器中。
然后我尝试运行该图像:
docker run -p 8050:8050 -v "s:/folder1/folder2/folder3/":"/data" <tag>
这会弹出一个窗口“Docker想要访问C\dc\Shared\folder1\folder2\folder3”,选择共享后,我可以选择共享或取消,在正确的位置创建了文件夹3,但出现错误:
docker: Error response from daemon: error while creating mount source path '/host_mnt/uC/dc/Shared/folder1/folder2/folder3/': mkdir /host_mnt/uC: operation not permitted.
如果我在C:驱动器上尝试一个位置,则该驱动器可以正常工作,而仅仅是共享驱动器给我带来了问题。
什么是挂载卷的正确方法,这样我便可以保存到该文件夹​​?谢谢

最佳答案

您的容器化应用应改为调用/data文件夹。

关于python - 如何在Windows的Docker中挂载卷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63409870/

相关文章:

python - Elasticsearch计算后将两个字段回填到一个新字段中

python - 如何计算列 Pandas 数据框中列表的平均值

python - 如何测试 SOAP Web 服务的 RPC?

windows - ucrtbase.dll : An invalid parameter was passed to a function that considers invalid parameters fatal

python - 提取向上指向的车道线

windows - 如何关闭 DwmExtendFrameIntoClientArea?

python-3.x - 无法将 PostgreSQL 与 Python3.6 连接,但与 Python2.7 的代码相同。问题意外

node.js - 如何在 Docker 容器中同时运行 Node.js 和 MongoDB 交互式 shell

git - 在 AWS EC2 实例上作为主机和私有(private) git 存储库在 dockerfile 中运行 git clone 时出现主机验证失败错误

docker - docker 卷何时可用于 CMD 脚本?