Docker与共享Windows文件夹 [英] Docker vs. Shared windows folders

查看:93
本文介绍了Docker与共享Windows文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从适用于Windows的Docker上的Docker容器中访问远程共享文件夹.

I'm trying to access a remotely shared folder from within a docker container on Docker for Windows.

在运行 dir \\ target \ share 的容器内部时,产生找不到网络路径.".可以从容器内部对目标执行ping操作,并可以从主机系统访问共享.

While inside the container running dir \\target\share produces "The network path was not found.". The target can be pinged from inside the container and from the host system the share is accessible.

所使用的图像是 microsoft/dotnet-framework:4.7.2-sdk ,我仅通过 -it 选项进行测试即可运行.

The image used is microsoft/dotnet-framework:4.7.2-sdk and I'm running it with just the -it option for testing.

要使它正常工作,我缺少什么?

What am I missing to get this to work?

推荐答案

SMB协议适用于同一LAN中的主机.Docker容器默认情况下在NAT之后具有虚拟网络接口,因此该容器不再位于同一LAN中.这就是为什么您可以ping通目标但无法访问共享文件夹的原因.

The SMB protocol works with hosts in the same LAN. A docker container, by default, has a virtual network interface behind a NAT, so the container is no longer in the same LAN. This is why you can ping the target, but you can't access the shared folder.

更简单的解决方案是将选项-network host 添加到 docker run 命令.这样,容器可以访问与主机相同的网络接口,并且不会创建任何虚拟接口.

The easier solution is to add the option --network host to the docker run command. In this way the container has access to the same network interfaces as the host and no virtual interface is created.

这篇关于Docker与共享Windows文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆