简体   繁体   English

如何在 Docker 中为 windows 安装卷?

[英]How to mount a volume in Docker for windows?

I'm trying to save data from my docker app to a host folder.我正在尝试将数据从我的 docker 应用程序保存到主机文件夹。 My dockerfile is:我的 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"]

I then build the image:然后我构建图像:

docker build <path> -t <tag>

And then run:然后运行:

docker run -p 8050:8050 <tag>

In order to save the output from the docker app, which I was trying to do like this为了从 docker 应用程序中保存 output,我试图这样做

pd.DataFrame(rows).to_excel('S:/Folder1/Folder2/Folder3/file.xlsx', index=False) 

I have to mount the volume, within Docker Settings>Resources>File Sharing I've added the directory 'S:/Folder1/Folder2/Folder3/' so that it can be mounted into Docker containers.我必须在 Docker 设置>资源>文件共享中挂载该卷,我已添加目录'S:/Folder1/Folder2/Folder3/',以便可以将其挂载到 Docker 容器中。

And then I tried to run the image:然后我尝试运行图像:

docker run -p 8050:8050 -v "s:/folder1/folder2/folder3/":"/data" <tag>

this pop ups a window "Docker wants to access to C\dc\Shared\folder1\folder2\folder3" And I can choose to share or cancel, after selecting share, folder 3 is created in the right location but I get the error:这会弹出一个 window “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.

If I try a location on my C: drive this works without problems, it's just the shared drive that is giving me problems.如果我在我的 C 上尝试一个位置:驱动这个工作没有问题,只是共享驱动器给我带来了问题。

What is the right way to mount the volume so I can then save to that folder?安装卷的正确方法是什么,以便我可以保存到该文件夹? Thank you谢谢

Your containerized app should call /data folder instead.您的容器化应用程序应该调用 /data 文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM