Sample Dockerfiles for Windows Server Core (#2428)

This commit is contained in:
Matt Thalman 2020-12-03 09:05:17 -06:00
Родитель 84d7ea7f88
Коммит 4670eaf615
6 изменённых файлов: 93 добавлений и 4 удалений

Просмотреть файл

@ -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"]

Просмотреть файл

@ -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"]

Просмотреть файл

@ -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"]

Просмотреть файл

@ -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"]

Просмотреть файл

@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Docker.Tests
.Select(imageData => new object[] { imageData });
}
[SkippableTheory("windowsservercore-ltsc2019")]
[Theory]
[MemberData(nameof(GetImageData))]
public async Task VerifyDotnetSample(SampleImageData imageData)
{
@ -49,7 +49,7 @@ namespace Microsoft.DotNet.Docker.Tests
});
}
[SkippableTheory("windowsservercore-ltsc2019")]
[Theory]
[MemberData(nameof(GetImageData))]
public async Task VerifyAspnetSample(SampleImageData imageData)
{

Просмотреть файл

@ -86,8 +86,10 @@ namespace Microsoft.DotNet.Docker.Tests
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()