Skip to content

Commit

Permalink
Sample Dockerfiles for Windows Server Core (dotnet#2428)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthalman committed Dec 7, 2020
1 parent 84d7ea7 commit 4670eaf
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 4 deletions.
19 changes: 19 additions & 0 deletions samples/aspnetapp/Dockerfile.windowsservercore-x64
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:5.0-windowsservercore-ltsc2019 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r win-x64

# copy everything else and build app
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r win-x64 --self-contained false --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:5.0-windowsservercore-ltsc2019 AS runtime
WORKDIR /app
COPY --from=build /app ./
ENTRYPOINT ["aspnetapp"]
29 changes: 29 additions & 0 deletions samples/aspnetapp/Dockerfile.windowsservercore-x64-slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# escape=`

# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:5.0-windowsservercore-ltsc2019 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore -r win-x64

# copy everything else and build app
COPY aspnetapp/. ./aspnetapp/
WORKDIR /source/aspnetapp
RUN dotnet publish -c release -o /app -r win-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true

# final stage/image
# Uses the ltsc2019 release; 20H2, 2004, 1909, 1809, and ltsc2016 are other choices
FROM mcr.microsoft.com/windows/servercore:ltsc2019 AS runtime
WORKDIR /app
COPY --from=build /app ./

ENV `
# Configure web servers to bind to port 80 when present
ASPNETCORE_URLS=http://+:80 `
# Enable detection of running in a container
DOTNET_RUNNING_IN_CONTAINER=true

ENTRYPOINT ["aspnetapp"]
17 changes: 17 additions & 0 deletions samples/dotnetapp/Dockerfile.windowsservercore-x64
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:5.0-windowsservercore-ltsc2019 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore -r win-x64

# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app -r win-x64 --self-contained false --no-restore

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime:5.0-windowsservercore-ltsc2019
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnetapp"]
22 changes: 22 additions & 0 deletions samples/dotnetapp/Dockerfile.windowsservercore-x64-slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://hub.docker.com/_/microsoft-dotnet
FROM mcr.microsoft.com/dotnet/sdk:5.0-windowsservercore-ltsc2019 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore -r win-x64

# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app -r win-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true

# final stage/image
# Uses the ltsc2019 release; 20H2, 2004, 1909, 1809, and ltsc2016 are other choices
FROM mcr.microsoft.com/windows/servercore:ltsc2019
WORKDIR /app
COPY --from=build /app .

# Enable detection of running in a container
ENV DOTNET_RUNNING_IN_CONTAINER=true

ENTRYPOINT ["dotnetapp"]
4 changes: 2 additions & 2 deletions tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static IEnumerable<object[]> GetImageData()
.Select(imageData => new object[] { imageData });
}

[SkippableTheory("windowsservercore-ltsc2019")]
[Theory]
[MemberData(nameof(GetImageData))]
public async Task VerifyDotnetSample(SampleImageData imageData)
{
Expand All @@ -49,7 +49,7 @@ await VerifySampleAsync(imageData, SampleImageType.Dotnetapp, (image, containerN
});
}

[SkippableTheory("windowsservercore-ltsc2019")]
[Theory]
[MemberData(nameof(GetImageData))]
public async Task VerifyAspnetSample(SampleImageData imageData)
{
Expand Down
6 changes: 4 additions & 2 deletions tests/Microsoft.DotNet.Docker.Tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ public static class TestData
new SampleImageData { OS = OS.NanoServer2004, Arch = Arch.Amd64, IsPublished = true },
new SampleImageData { OS = OS.NanoServer20H2, Arch = Arch.Amd64, IsPublished = true },

new SampleImageData { OS = OS.NanoServer20H2, Arch = Arch.Amd64, DockerfileSuffix = "nanoserver-x64" },
new SampleImageData { OS = OS.NanoServer20H2, Arch = Arch.Amd64, DockerfileSuffix = "nanoserver-x64-slim" },
new SampleImageData { OS = OS.NanoServer20H2, Arch = Arch.Amd64, DockerfileSuffix = "nanoserver-x64" },
new SampleImageData { OS = OS.NanoServer20H2, Arch = Arch.Amd64, DockerfileSuffix = "nanoserver-x64-slim" },
new SampleImageData { OS = OS.ServerCoreLtsc2019, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-x64" },
new SampleImageData { OS = OS.ServerCoreLtsc2019, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-x64-slim" },
};

public static IEnumerable<ProductImageData> GetImageData()
Expand Down

0 comments on commit 4670eaf

Please sign in to comment.