Recently someone asked me how can he adds a secondary IP address to a Windows Container hosting multiple IIS websites.
Adding a secondary IP Address to a Windows Container can be done using a few PowerShell cmdlets In a matter of a few minutes as you will see below.
Requirements
- Transparent network – For the Container to respond to multiple IP addresses the container needs to be on a Transparent network, for setup see my article http://www.deploycontainers.com/2017/08/26/windows-containers-networking-explained/
- Windows Container with PowerShell – I’ll use Windows Server 2016 1709
Get Started
In my case, I have a Windows Server Core 2016 1709 Container and my container host has the Network configuration below.
Next, I’ll create a Container with the Transparent network above
docker run -it --name test --network=MyTransparentNetwork microsoft/windowsservercore:1709 powershell
From the Container, I’ll run the cmdlet below to get the Network Adapter Interface ID
Get-NetAdapter
In the final step, I’ll assign a secondary IP
New-NetIPAddress -InterfaceIndex 23 -IPAddress 192.168.0.26 -PrefixLength 24 -DefaultGateway 192.168.0.1
And as you can see below. The new secondary IP address Is set.
This article Is based on the blog post below where I used it on Windows Nano Server 2016.
https://www.ntweekly.com/2017/05/05/add-secondary-ip-address-to-windows-nano-server-2016/