简体   繁体   English

将Windows目录共享到Linux Docker容器

[英]Share windows directory to Linux docker container

I've been trying the whole day to accomplish a simplistic example of sharing a Windows directory to Linux container running on Windows Docker host. 我整天都在尝试完成一个简单的示例,将Windows目录共享给在Windows Docker主机上运行的Linux容器。 Have read all the guidelines and run the following: 阅读所有指南并运行以下命令:

docker run -it --rm -p 5002:80 --name mount-test --mount type=bind,source=D:\DockerArea\PortScanner,target=/app/PortScannerWorkingDirectory barebonewebapi:latest

The origin PortScanner directory on host machine has got some text file in it. 主机上的原始PortScanner目录中包含一些文本文件。 The container is created successfully. 容器创建成功。 The issue is that when I'm trying to 问题是当我试图

docker exec -it mount-test /bin/bash 

and then list the mounted directory in the container PortScannerWorkingDirectory - it just shows that it's empty. 然后在容器PortScannerWorkingDirectory列出已安装的目录-它只是显示它为空。 Nor the C# code can read the contents of the host file in the mapped directory. C#代码也无法读取映射目录中主机文件的内容。 Am I missing something simple here? 我在这里缺少简单的东西吗? I feel like I got stuck and can't share files on the host Windows machine to Linux container. 我感觉好像被卡住了,无法将Windows主机上的文件共享到Linux容器。

After several days of dealing with the issue I've found quite apparent answer. 经过几天的处理,我找到了很明显的答案。 Although I had had C and D drives already shared to Docker in Docker settings I did an experiment and re-shared both drives (there's a special button Reset Credentials for that purpose in Docker agent settings for Windows). 尽管我已经在Docker设置中将C和D驱动器共享给Docker,但我进行了一次实验并重新共享了这两个驱动器 (在Windows的Docker代理设置中,有一个特殊的按钮Reset Credentials用于此目的)。 After that the issue is resolved. 之后,问题解决了。 So saving it here with the hope that it may help someone else since this seems to be a glitch with permissions or similar. 因此将其保存在此处,希望对其他人有所帮助,因为这似乎是权限或类似问题的小故障。 The issue is quite hard to diagnose - when there's an issue the Docker container just silently writes into its writable layer and no error pops up. 这个问题很难诊断-当出现问题时,Docker容器只是默默地写入其可写层,而不会弹出错误。

Go to the docker settings -> shared drives -> reset credentials . 转到docker settings -> shared drives -> reset credentials and then click the drive and click apply button. 然后单击驱动器,然后单击“应用”按钮。

then execute following command as suggested by docker 然后按照docker的建议执行以下命令

docker run --rm -v c:/Users:/data alpine ls /data

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

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