You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Docker IIS容器中绑定多IP并运行多个网站?

Hey there! As someone who’s worked with IIS and Docker quite a bit, let’s break this down step by step for you—since you’re new to Docker, I’ll keep things straightforward and avoid overly technical jargon where I can.

Step 1: Bind Multiple IPs to Your IIS Docker Container

By default, Windows Docker containers use a NAT network and only get one IP address. To assign multiple IPs, we’ll use a custom network and add extra IPs to the container after launch:

  • First, create a custom NAT network (we’ll define a subnet so we have full control over IP assignments):
    docker network create -d nat --subnet=192.168.10.0/24 --gateway=192.168.10.1 my-iis-network
    
  • Launch your IIS container with the first IP address assigned:
    docker run -d --name my-iis-container --network my-iis-network --ip 192.168.10.10 mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019
    
  • Add a second IP to the same container by connecting it again to the custom network with a new IP:
    docker network connect --ip 192.168.10.11 my-iis-network my-iis-container
    
  • Verify the container has both IPs by running:
    docker exec my-iis-container ipconfig
    
    You should see both 192.168.10.10 and 192.168.10.11 listed under the Ethernet adapter.
Step 2: Set Up Multiple Websites Inside the IIS Container

Now that your container has multiple IPs, let’s configure separate websites to bind to each one. We’ll use PowerShell inside the container to set this up:

  • First, open an interactive PowerShell session in the container:
    docker exec -it my-iis-container powershell
    
  • Create directories and sample content for each website:
    # Create Site 1 files
    New-Item -Path C:\inetpub\site1 -ItemType Directory
    New-Item -Path C:\inetpub\site1\index.html -Value "<h1>Welcome to Site 1 (IP: 192.168.10.10)</h1>"
    
    # Create Site 2 files
    New-Item -Path C:\inetpub\site2 -ItemType Directory
    New-Item -Path C:\inetpub\site2\index.html -Value "<h1>Welcome to Site 2 (IP: 192.168.10.11)</h1>"
    
  • Use IIS’s PowerShell module to create each website and bind it to a specific IP:
    Import-Module WebAdministration
    
    # Create Site 1 bound to 192.168.10.10:80
    New-Website -Name "Site1" -Port 80 -IPAddress "192.168.10.10" -PhysicalPath "C:\inetpub\site1"
    
    # Create Site 2 bound to 192.168.10.11:80
    New-Website -Name "Site2" -Port 80 -IPAddress "192.168.10.11" -PhysicalPath "C:\inetpub\site2"
    
Step 3: Test Access to Your Websites
  • From your Docker host, test each site using their container IPs:
    # Test Site 1
    Invoke-WebRequest http://192.168.10.10
    
    # Test Site 2
    Invoke-WebRequest http://192.168.10.11
    
  • If you want external devices to access these sites, you’ll need to map the container’s IPs/ports to your host’s external IPs. For example, if your host has IPs 10.0.0.10 and 10.0.0.11, launch the container with:
    docker run -d --name my-iis-container -p 10.0.0.10:80:80 -p 10.0.0.11:80:80 --network my-iis-network --ip 192.168.10.10 mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019
    
    Then external users can visit http://10.0.0.10 and http://10.0.0.11 to see each site.
Pro Tip: Automate with a Dockerfile

If you don’t want to run these commands every time, you can create a Dockerfile to pre-configure your websites:

FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019

# Create website directories and content
RUN New-Item -Path C:\inetpub\site1 -ItemType Directory; `
    New-Item -Path C:\inetpub\site1\index.html -Value "<h1>Welcome to Site 1</h1>"; `
    New-Item -Path C:\inetpub\site2 -ItemType Directory; `
    New-Item -Path C:\inetpub\site2\index.html -Value "<h1>Welcome to Site 2</h1>"

# Configure IIS websites
RUN Import-Module WebAdministration; `
    New-Website -Name "Site1" -Port 80 -IPAddress "192.168.10.10" -PhysicalPath "C:\inetpub\site1"; `
    New-Website -Name "Site2" -Port 80 -IPAddress "192.168.10.11" -PhysicalPath "C:\inetpub\site2"

Build the custom image with:

docker build -t my-custom-iis .

Then launch your container using this image and assign multiple IPs as we did earlier.


内容的提问来源于stack exchange,提问作者user1550159

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:00:53