This guide walks you through to building a simple Docker Windows Server Core container running the latest 1803 version that comes with a lot of enhancements (such as: half in size :), networking improvements, etc.). The good thing is that the dotnet framework SDK image on Docker Hub with tag 4.7.2-sdk-windowsservercore-1803
already allows room for us to target either 4.0
, 4.5.2
, 4.6.2
or 4.7.2
to build our app, you can read more about it here. We can run this on the image microsoft/aspnet:4.7.2-windowsservercore-1803
.
- File -> New -> Project
- Select ASP.NET Framework
- Target any .NET Frameworks from this list -
4.0
,4.5.2
,4.6.2
,4.7.2
- Target any .NET Frameworks from this list -
- Create a simple Dockerfile similar to the sample here
FROM microsoft/dotnet-framework:4.7.2-sdk-windowsservercore-1803 AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY *.sln .
COPY <path-to>/*.csproj ./<path-to>/
COPY <path-to>/*.config ./<path-to>/
RUN nuget restore
# copy everything else and build app
COPY <path-to>/. ./<path-to>/
WORKDIR /app/<path-to>
RUN msbuild /p:Configuration=Release
FROM microsoft/aspnet:4.7.2-windowsservercore-1803 AS runtime
WORKDIR /inetpub/wwwroot
COPY --from=build /app/<path-to>/. ./
- Run
docker build --pull -t <docker image name> .
in the CLI to build a docker image- Make sure you have set Docker to run Windows containers
- Run
docker run --rm -it -p 8000:80 <docker image name>
in the CLI to run the docker container - Follow this guide to view the ASP.NET app in a running container on Windows or follow the steps below:
- Open up another command prompt.
- Check the name of the conatiner by running
docker ps
and look at the CONTAINER ID or NAMES section that maps to your conatiner image - Run
docker exec <container name> ipconfig
- Copy the container IP address and paste into your browser (for example,
172.29.245.43
).