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

VS 2017中如何将三个Web项目部署到单个Docker容器的IIS中?

Can I deploy three web projects to a single IIS container with virtual apps in VS 2017 15.6.4?

Absolutely, you can pull this off! Visual Studio’s default Docker support usually ties one project to one container, but with a custom Dockerfile and a bit of manual setup, you can package all three web projects into a single IIS container with the exact site structure you described. Here’s a step-by-step breakdown:

Step 1: Publish each web project first

First, generate deployable output for all three projects:

  • Right-click Web Project 1 in Solution Explorer → Select Publish → Choose a folder target (e.g., ./publish/Web1) and publish it as your root site content.
  • Repeat this for Web Project 2, publishing to ./publish/Web2 (for the Admin virtual app).
  • Do the same for Web Project 3, publishing to ./publish/Web3 (for the Campaign virtual app).

Make sure all projects are published in the same configuration (like Release) and target a .NET framework compatible with your chosen IIS container image.

Step 2: Create a custom Dockerfile

In your solution root directory, create a Dockerfile with the following content. Adjust the base image and ASP.NET feature installation to match your project’s framework version:

# Use the appropriate IIS base image (match your Windows host version and .NET framework)
FROM mcr.microsoft.com/windows/servercore/iis:windowsservercore-ltsc2019

# Install ASP.NET 4.8 (modify this if you're using an older framework like 4.7.2)
RUN dism /online /enable-feature /all /featurename:IIS-ASPNET45

# Create directories for virtual app content
RUN mkdir C:\inetpub\admin
RUN mkdir C:\inetpub\campaign

# Copy root site (Web Project 1) content to IIS's default wwwroot
COPY ./publish/Web1/ C:\inetpub\wwwroot\

# Copy Web Project 2 content to the admin directory
COPY ./publish/Web2/ C:\inetpub\admin\

# Copy Web Project 3 content to the campaign directory
COPY ./publish/Web3/ C:\inetpub\campaign\

# Create the Admin virtual application under the Default Web Site
RUN %windir%\system32\inetsrv\appcmd add app /site.name:"Default Web Site" /path:/Admin /physicalPath:C:\inetpub\admin

# Create the Campaign virtual application
RUN %windir%\system32\inetsrv\appcmd add app /site.name:"Default Web Site" /path:/Campaign /physicalPath:C:\inetpub\campaign

# Expose port 80 for web traffic
EXPOSE 80

For ASP.NET Core projects:

If your web projects are ASP.NET Core, add this line after installing IIS features to set up the ASP.NET Core Module:

RUN powershell -Command Invoke-WebRequest -Uri https://dotnet.microsoft.com/download/dotnet-core/scripts/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; ./dotnet-install.ps1 -Version <your-core-version> -InstallDir 'C:\Program Files\dotnet'; Remove-Item dotnet-install.ps1

Also ensure your published content includes the required web.config for IIS integration.

Step 3: Build and run the container in Visual Studio 2017

  • In Visual Studio, go to File → Open → File and select the Dockerfile you created.
  • Right-click the Dockerfile in Solution Explorer → Select Build Image.
  • Once the image is built, right-click the Dockerfile again → Select Run Container to start the IIS container with your sites and virtual apps.

You can verify the setup by visiting http://localhost (root site), http://localhost/Admin, and http://localhost/Campaign in your browser.

Key considerations

  • Windows version compatibility: Ensure the base image’s Windows version matches your host machine’s (e.g., if you’re on Windows 10 1809, use windowsservercore-ltsc2019). Mismatched versions can cause deployment errors.
  • Permissions: Double-check that the IIS_IUSRS group has read access to the virtual app directories in the container (the base image usually handles this, but it’s a common fix for 403 errors).
  • Updating projects: Whenever you modify your web projects, republish them to the ./publish folders and rebuild the Docker image to apply changes.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:17:03