docker - 如何使 docker 容器与我的本地主机在同一 LAN 上运行?
问题描述
我正在尝试使 docker 容器在与本地主机相同的 LAN 上运行,因此 nmap 可以成功扫描 LAN 设备。
但是,当我按照以下这些步骤操作时,我在路径X:\Program Files\Docker\Docker\resources中找不到MobyLinux.ps1。
有什么我错过的吗?谢谢!
Windows 10 PROFESSIONAL/ENTERPRISE
**Create vSwitch with physical network adapter**
1. Open Hyper-V Manager
2. Action list- > Open Virtual Switch Manager
3. Create new virtual switch -> select Type: External
4. Assign your physical network adapter to the vSwitch
5. Check "Allow management operating system to share this network adapter" and apply change
6. Go to Control Panel\All Control Panel Items\Network Connections.
7. Check the vEthernet you just created, and make sure the IPV4 setting is correct. (sometimes the dhcp setting will be empty and you need to reset again here)
8. Go back to Hyper-V Manager, and go into Setting page of MobyLinuxVM (ensure it's shut down, if it's not, Quit Docker)
9. Add Hardware > Network Adapter, select the vSwitch you just created and apply change
**Modify Docker source code**
1. Find the MobyLinux creation file: MobyLinux.ps1 (normally it's located at: X:\Program Files\Docker\Docker\resources)
2. Edit the file, and find the function: function New-MobyLinuxVM
3. Find below line in the function: $vmNetAdapter = $vm | Hyper-V\Get-VMNetworkAdapter
Update it to: $vmNetAdapter = $vm | Hyper-V\Get-VMNetworkAdapter | Select-Object -First 1
4. Save file by administrator
5. Restart Docker, and the container should run on the LAN now.
环境: 操作系统:Windows 10 Professional 20H2 19042.1110
Docker 版本:Docker Engine - Community V20.10.7(Hyper-V 后端)
解决方案
推荐阅读
- mongodb - 获取 MongoDB 集合的数组中嵌入文档的总数
- scala - 当DataFrame为空时抛出AnalysisException(没有这样的结构字段)
- swift - 如何使用 Alamofire (post) 上传图片?
- firebase-realtime-database - AuthUI 的初始导航视图控制器在 Xcode 10.2 下不起作用
- c# - 从 WCF 运行 Exe
- sql - SQL 行在不同组中聚合每次文本出现在日志中
- javascript - 如何使用jsPDF-autotable从pdf标题中的路径显示图像
- matplotlib - 如何使用 PyPlot 在 Atom 中显示图形
- arrays - 元素不会被推送到 stream() 中的数组
- javascript - 如何在反应js中按字母顺序对表格数据进行排序?