Live is streaming live. Watch now.

A complete Dockerfile with no hidden layers

This is a Dockerfile that “installs” an entire .NET environment. The only layer brought in, is the required base file system. Which makes the resulting container compatible with the host it is running on (Windows Server 2019 in this example). This is not meant to be used in a project but more an example to see what the Microsoft distributed images like or microsoft/iis are doing “under the hood”.

High level steps: - Create a base file system - Set PowerShell as shell - Install .NET runtime - Install IIS and features - Copy in app - Set the entrypoint for the running container


# escape=`

# use powershell to build and run the container
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'SilentlyContinue'; $ProgressPreference = 'SilentlyContinue';"]

# ******************************************************
# Install .NET 3.5

# Download and expand the dotnet framework
RUN Invoke-WebRequest -OutFile `
RUN tar -zxf
RUN Remove-Item -Force
# Install the package
RUN DISM /Online /Quiet /Add-Package /PackagePath:.\
# Clean up
RUN del
RUN Remove-Item -Force -Recurse ${Env:TEMP}\*
# ^^^ runtime image

# ******************************************************
# Prepare container for hosting ASP.NET web apps

# Install IIS
RUN Add-WindowsFeature Web-Server
# Install ASP.NET
RUN Add-WindowsFeature Web-Asp-Net
# Clean out default site
RUN Remove-Item -Recurse C:\inetpub\wwwroot\*
# Download ServiceMonitor.exe
RUN Invoke-WebRequest -OutFile C:\ServiceMonitor.exe `
# Configure the app pool the appropriate .NET version
RUN c:\Windows\System32\inetsrv\appcmd set apppool / /managedRuntimeVersion:v2.0
# ^^^ aspnet image

# Copy our application's published bits into the container's /inetpub/wwwroot
COPY ./OldWebApp/Publish/ /inetpub/wwwroot

# Since this container hosts a webserver we're exposing port 80

# ServiceMonitor.exe starts and runs the w3svc Windows service
ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"]
# ^^^ our image
On This Page