首页 > 解决方案 > 如何使 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 后端)

参考: https ://hub.docker.com/r/qtimmylin/evt_platform/

标签: dockermoby

解决方案


推荐阅读