Windows Docker 固定容器IP地址 透明網絡驅動程序


測試環境:

 Windows Server 2019數據中心版本

步驟一:

1. 獲取當前所有的網卡

PS C:\> Get-NetAdapter

結果:
返回所有的網卡信息,選擇你需要開發的網卡名稱,注意這里的網卡不能是虛擬網卡,應該是未進行虛擬化的物理網卡。

2.創建Docker的透明網絡驅動  

docker network create -d "transparent" --subnet 192.168.0.0/24 --gateway 192.168.0.1 -o com.docker.network.windowsshim.dnsservers="192.168.0.254" -o com.docker.network.windowsshim.interface="NIC2" my_transparent

意思就是通過NIC2創建一個透明網絡,可進行物理交換機的訪問。其中DNS的地址為192.168.0.254,網關地址為192.168.0.1,子網掩碼:255.255.255.0

3.指定改網絡運行容器

docker run  -v c:\app:c:\app -it -d --ip=192.168.0.92 --net=my_transparent --name=ibms ibms:v1.50

指定容器運行的IP地址為192.168.0.92,如果你需要動態分配IP就不指定ip參數。

4.查看運行結果

docker exec -it ibms cmd 

然后運行命令:

ipconfig /all

獲得結果:

Windows IP Configuration

Host Name . . . . . . . . . . . . : bb304d962c2d
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter vEthernet (Ethernet):

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter #4
Physical Address. . . . . . . . . : 00-15-5D-AF-F2-5A
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::2904:8bb9:e118:70a7%46(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.0.92(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
DNS Servers . . . . . . . . . . . : 192.168.0.254
NetBIOS over Tcpip. . . . . . . . : Disabled

驗證正確!  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM