From d2093aac49cb78be0b8d46d25387db6b7f11a14b Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Fri, 31 Mar 2023 10:06:30 -0700 Subject: [PATCH 01/11] Remove single file publishing --- samples/aspnetapp/Dockerfile.alpine-slim | 2 +- samples/aspnetapp/aspnetapp/aspnetapp.csproj | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/aspnetapp/Dockerfile.alpine-slim b/samples/aspnetapp/Dockerfile.alpine-slim index 9e10977a8b..5cb3898bf4 100644 --- a/samples/aspnetapp/Dockerfile.alpine-slim +++ b/samples/aspnetapp/Dockerfile.alpine-slim @@ -8,7 +8,7 @@ RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app --use-current-runtime --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true +RUN dotnet publish --use-current-runtime --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true # To enable globalization: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md diff --git a/samples/aspnetapp/aspnetapp/aspnetapp.csproj b/samples/aspnetapp/aspnetapp/aspnetapp.csproj index 3c75ff5cdc..ac48ba8dd5 100644 --- a/samples/aspnetapp/aspnetapp/aspnetapp.csproj +++ b/samples/aspnetapp/aspnetapp/aspnetapp.csproj @@ -5,6 +5,7 @@ enable enable 57393389627611478466 + true From 4908e50d19ca39db993309cad3e4c8320f7e30ab Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Fri, 31 Mar 2023 15:57:20 -0700 Subject: [PATCH 02/11] Clean up Dockerfiles --- manifest.samples.json | 6 ++--- samples/aspnetapp/Dockerfile | 6 +++-- samples/aspnetapp/Dockerfile.alpine | 7 +++-- samples/aspnetapp/Dockerfile.alpine-arm32 | 19 ------------- .../aspnetapp/Dockerfile.alpine-arm32-slim | 19 ------------- samples/aspnetapp/Dockerfile.alpine-arm64 | 19 ------------- .../aspnetapp/Dockerfile.alpine-arm64-slim | 19 ------------- samples/aspnetapp/Dockerfile.alpine-icu | 7 +++-- samples/aspnetapp/Dockerfile.alpine-non-root | 4 ++- samples/aspnetapp/Dockerfile.alpine-slim | 6 +++-- samples/aspnetapp/Dockerfile.alpine-x64 | 19 ------------- samples/aspnetapp/Dockerfile.alpine-x64-slim | 19 ------------- samples/aspnetapp/Dockerfile.chiseled | 8 +++--- samples/aspnetapp/Dockerfile.debian-arm32 | 17 ------------ samples/aspnetapp/Dockerfile.debian-arm64 | 17 ------------ samples/aspnetapp/Dockerfile.debian-x64 | 17 ------------ samples/aspnetapp/Dockerfile.debian-x64-slim | 17 ------------ samples/aspnetapp/Dockerfile.nanoserver | 23 ++++++++++++++++ samples/aspnetapp/Dockerfile.nanoserver-slim | 9 ++++--- samples/aspnetapp/Dockerfile.nanoserver-x64 | 19 ------------- .../aspnetapp/Dockerfile.nanoserver-x64-slim | 26 ------------------ samples/aspnetapp/Dockerfile.ubuntu | 19 +++++++++++++ samples/aspnetapp/Dockerfile.ubuntu-x64 | 17 ------------ samples/aspnetapp/Dockerfile.ubuntu-x64-slim | 17 ------------ ...rcore-x64 => Dockerfile.windowsservercore} | 8 +++--- ...Dockerfile.windowsservercore-containeruser | 21 --------------- ...s-x64 => Dockerfile.windowsservercore-iis} | 8 +++--- .../Dockerfile.windowsservercore-x64-slim | 26 ------------------ samples/complexapp/Dockerfile | 8 +++--- .../complexapp/complexapp/complexapp.csproj | 1 + samples/dotnetapp/Dockerfile | 6 +++-- samples/dotnetapp/Dockerfile.alpine | 21 +++++++++++++++ samples/dotnetapp/Dockerfile.alpine-arm32 | 27 ------------------- .../dotnetapp/Dockerfile.alpine-arm32-slim | 27 ------------------- samples/dotnetapp/Dockerfile.alpine-arm64 | 27 ------------------- .../dotnetapp/Dockerfile.alpine-arm64-slim | 27 ------------------- samples/dotnetapp/Dockerfile.alpine-slim | 21 +++++++++++++++ samples/dotnetapp/Dockerfile.alpine-x64 | 27 ------------------- samples/dotnetapp/Dockerfile.alpine-x64-slim | 27 ------------------- samples/dotnetapp/Dockerfile.chiseled | 6 +++-- samples/dotnetapp/Dockerfile.debian-arm32 | 17 ------------ samples/dotnetapp/Dockerfile.debian-arm64 | 17 ------------ samples/dotnetapp/Dockerfile.debian-x64 | 17 ------------ samples/dotnetapp/Dockerfile.debian-x64-slim | 17 ------------ ...e.nanoserver-x64 => Dockerfile.nanoserver} | 11 ++++---- samples/dotnetapp/Dockerfile.nanoserver-slim | 24 +++++++++++++++++ .../dotnetapp/Dockerfile.nanoserver-x64-slim | 21 --------------- samples/dotnetapp/Dockerfile.ubuntu | 19 +++++++++++++ samples/dotnetapp/Dockerfile.ubuntu-arm32 | 17 ------------ samples/dotnetapp/Dockerfile.ubuntu-arm64 | 17 ------------ samples/dotnetapp/Dockerfile.ubuntu-x64 | 17 ------------ samples/dotnetapp/Dockerfile.ubuntu-x64-slim | 17 ------------ .../Dockerfile.windowsservercore-x64 | 3 ++- .../Dockerfile.windowsservercore-x64-slim | 7 ++--- samples/dotnetapp/dotnetapp.csproj | 1 + samples/globalapp/Dockerfile | 2 +- 56 files changed, 197 insertions(+), 671 deletions(-) delete mode 100644 samples/aspnetapp/Dockerfile.alpine-arm32 delete mode 100644 samples/aspnetapp/Dockerfile.alpine-arm32-slim delete mode 100644 samples/aspnetapp/Dockerfile.alpine-arm64 delete mode 100644 samples/aspnetapp/Dockerfile.alpine-arm64-slim delete mode 100644 samples/aspnetapp/Dockerfile.alpine-x64 delete mode 100644 samples/aspnetapp/Dockerfile.alpine-x64-slim delete mode 100644 samples/aspnetapp/Dockerfile.debian-arm32 delete mode 100644 samples/aspnetapp/Dockerfile.debian-arm64 delete mode 100644 samples/aspnetapp/Dockerfile.debian-x64 delete mode 100644 samples/aspnetapp/Dockerfile.debian-x64-slim create mode 100644 samples/aspnetapp/Dockerfile.nanoserver delete mode 100644 samples/aspnetapp/Dockerfile.nanoserver-x64 delete mode 100644 samples/aspnetapp/Dockerfile.nanoserver-x64-slim create mode 100644 samples/aspnetapp/Dockerfile.ubuntu delete mode 100644 samples/aspnetapp/Dockerfile.ubuntu-x64 delete mode 100644 samples/aspnetapp/Dockerfile.ubuntu-x64-slim rename samples/aspnetapp/{Dockerfile.windowsservercore-x64 => Dockerfile.windowsservercore} (59%) delete mode 100644 samples/aspnetapp/Dockerfile.windowsservercore-containeruser rename samples/aspnetapp/{Dockerfile.windowsservercore-iis-x64 => Dockerfile.windowsservercore-iis} (85%) delete mode 100644 samples/aspnetapp/Dockerfile.windowsservercore-x64-slim create mode 100644 samples/dotnetapp/Dockerfile.alpine delete mode 100644 samples/dotnetapp/Dockerfile.alpine-arm32 delete mode 100644 samples/dotnetapp/Dockerfile.alpine-arm32-slim delete mode 100644 samples/dotnetapp/Dockerfile.alpine-arm64 delete mode 100644 samples/dotnetapp/Dockerfile.alpine-arm64-slim create mode 100644 samples/dotnetapp/Dockerfile.alpine-slim delete mode 100644 samples/dotnetapp/Dockerfile.alpine-x64 delete mode 100644 samples/dotnetapp/Dockerfile.alpine-x64-slim delete mode 100644 samples/dotnetapp/Dockerfile.debian-arm32 delete mode 100644 samples/dotnetapp/Dockerfile.debian-arm64 delete mode 100644 samples/dotnetapp/Dockerfile.debian-x64 delete mode 100644 samples/dotnetapp/Dockerfile.debian-x64-slim rename samples/dotnetapp/{Dockerfile.nanoserver-x64 => Dockerfile.nanoserver} (52%) create mode 100644 samples/dotnetapp/Dockerfile.nanoserver-slim delete mode 100644 samples/dotnetapp/Dockerfile.nanoserver-x64-slim create mode 100644 samples/dotnetapp/Dockerfile.ubuntu delete mode 100644 samples/dotnetapp/Dockerfile.ubuntu-arm32 delete mode 100644 samples/dotnetapp/Dockerfile.ubuntu-arm64 delete mode 100644 samples/dotnetapp/Dockerfile.ubuntu-x64 delete mode 100644 samples/dotnetapp/Dockerfile.ubuntu-x64-slim diff --git a/manifest.samples.json b/manifest.samples.json index b75707ba4b..c8233b409b 100644 --- a/manifest.samples.json +++ b/manifest.samples.json @@ -31,7 +31,7 @@ }, "platforms": [ { - "dockerfile": "samples/dotnetapp/Dockerfile.alpine-x64-slim", + "dockerfile": "samples/dotnetapp/Dockerfile.alpine-slim", "os": "linux", "osVersion": "alpine", "tags": { @@ -40,7 +40,7 @@ }, { "architecture": "arm", - "dockerfile": "samples/dotnetapp/Dockerfile.alpine-arm32-slim", + "dockerfile": "samples/dotnetapp/Dockerfile.alpine-slim", "os": "linux", "osVersion": "alpine", "tags": { @@ -50,7 +50,7 @@ }, { "architecture": "arm64", - "dockerfile": "samples/dotnetapp/Dockerfile.alpine-arm64-slim", + "dockerfile": "samples/dotnetapp/Dockerfile.alpine-slim", "os": "linux", "osVersion": "alpine", "tags": { diff --git a/samples/aspnetapp/Dockerfile b/samples/aspnetapp/Dockerfile index 0f3801ef33..36050e1f55 100644 --- a/samples/aspnetapp/Dockerfile +++ b/samples/aspnetapp/Dockerfile @@ -1,4 +1,5 @@ -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /source @@ -8,7 +9,8 @@ RUN dotnet restore --use-current-runtime # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app --use-current-runtime --self-contained false --no-restore +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:7.0 diff --git a/samples/aspnetapp/Dockerfile.alpine b/samples/aspnetapp/Dockerfile.alpine index 22c36345b4..85b4b31aab 100644 --- a/samples/aspnetapp/Dockerfile.alpine +++ b/samples/aspnetapp/Dockerfile.alpine @@ -1,3 +1,5 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build WORKDIR /source @@ -8,9 +10,10 @@ RUN dotnet restore --use-current-runtime # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime -c Release --self-contained false --no-restore -o /app +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app -# To enable globalization: + +# Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine diff --git a/samples/aspnetapp/Dockerfile.alpine-arm32 b/samples/aspnetapp/Dockerfile.alpine-arm32 deleted file mode 100644 index 969bc157ad..0000000000 --- a/samples/aspnetapp/Dockerfile.alpine-arm32 +++ /dev/null @@ -1,19 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-musl-arm - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-musl-arm --self-contained false --no-restore - -# To enable globalization: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md -# final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine-arm32v7 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.alpine-arm32-slim b/samples/aspnetapp/Dockerfile.alpine-arm32-slim deleted file mode 100644 index 930b79a603..0000000000 --- a/samples/aspnetapp/Dockerfile.alpine-arm32-slim +++ /dev/null @@ -1,19 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-musl-arm /p:PublishReadyToRun=true - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-musl-arm --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# To enable globalization: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-arm32v7 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.alpine-arm64 b/samples/aspnetapp/Dockerfile.alpine-arm64 deleted file mode 100644 index 02f87b9dac..0000000000 --- a/samples/aspnetapp/Dockerfile.alpine-arm64 +++ /dev/null @@ -1,19 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-musl-arm64 - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-musl-arm64 --self-contained false --no-restore - -# To enable globalization: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md -# final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine-arm64v8 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.alpine-arm64-slim b/samples/aspnetapp/Dockerfile.alpine-arm64-slim deleted file mode 100644 index 0f8185d1f5..0000000000 --- a/samples/aspnetapp/Dockerfile.alpine-arm64-slim +++ /dev/null @@ -1,19 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-musl-arm64 /p:PublishReadyToRun=true - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-musl-arm64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# To enable globalization: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-arm64v8 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.alpine-icu b/samples/aspnetapp/Dockerfile.alpine-icu index 5a5948d4ad..08f50de9e0 100644 --- a/samples/aspnetapp/Dockerfile.alpine-icu +++ b/samples/aspnetapp/Dockerfile.alpine-icu @@ -1,3 +1,5 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build WORKDIR /source @@ -8,9 +10,10 @@ RUN dotnet restore --use-current-runtime # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime -c Release --self-contained false --no-restore -o /app +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app -# To learn about globalization: + +# Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine diff --git a/samples/aspnetapp/Dockerfile.alpine-non-root b/samples/aspnetapp/Dockerfile.alpine-non-root index e22fc83a57..f9b3cb7a57 100644 --- a/samples/aspnetapp/Dockerfile.alpine-non-root +++ b/samples/aspnetapp/Dockerfile.alpine-non-root @@ -1,3 +1,5 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/nightly/sdk:8.0-preview-alpine AS build ARG TARGETARCH WORKDIR /source @@ -11,7 +13,7 @@ COPY aspnetapp/. . RUN dotnet publish -a $TARGETARCH --self-contained false --no-restore -o /app -# To enable globalization: +# Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image # .NET 8 tag includes `-preview` diff --git a/samples/aspnetapp/Dockerfile.alpine-slim b/samples/aspnetapp/Dockerfile.alpine-slim index 5cb3898bf4..c0734f8095 100644 --- a/samples/aspnetapp/Dockerfile.alpine-slim +++ b/samples/aspnetapp/Dockerfile.alpine-slim @@ -1,4 +1,5 @@ -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build WORKDIR /source @@ -10,7 +11,8 @@ RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true COPY aspnetapp/. . RUN dotnet publish --use-current-runtime --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true -# To enable globalization: + +# Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine diff --git a/samples/aspnetapp/Dockerfile.alpine-x64 b/samples/aspnetapp/Dockerfile.alpine-x64 deleted file mode 100644 index bf4d60bb74..0000000000 --- a/samples/aspnetapp/Dockerfile.alpine-x64 +++ /dev/null @@ -1,19 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-musl-x64 - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-musl-x64 --self-contained false --no-restore - -# To enable globalization: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md -# final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.alpine-x64-slim b/samples/aspnetapp/Dockerfile.alpine-x64-slim deleted file mode 100644 index 76fbcdc55d..0000000000 --- a/samples/aspnetapp/Dockerfile.alpine-x64-slim +++ /dev/null @@ -1,19 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-musl-x64 /p:PublishReadyToRun=true - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# To enable globalization: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.chiseled b/samples/aspnetapp/Dockerfile.chiseled index cef308cbb4..765ab5b88c 100644 --- a/samples/aspnetapp/Dockerfile.chiseled +++ b/samples/aspnetapp/Dockerfile.chiseled @@ -1,4 +1,5 @@ -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build WORKDIR /source @@ -8,10 +9,11 @@ RUN dotnet restore --use-current-runtime # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app --use-current-runtime --self-contained false --no-restore +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + # final stage/image FROM mcr.microsoft.com/dotnet/nightly/aspnet:7.0-jammy-chiseled WORKDIR /app COPY --from=build /app . -ENTRYPOINT ["dotnet", "aspnetapp.dll"] +ENTRYPOINT ["./aspnetapp.dll"] diff --git a/samples/aspnetapp/Dockerfile.debian-arm32 b/samples/aspnetapp/Dockerfile.debian-arm32 deleted file mode 100644 index e66099cde9..0000000000 --- a/samples/aspnetapp/Dockerfile.debian-arm32 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-arm - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-arm --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim-arm32v7 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.debian-arm64 b/samples/aspnetapp/Dockerfile.debian-arm64 deleted file mode 100644 index 679b2fc16c..0000000000 --- a/samples/aspnetapp/Dockerfile.debian-arm64 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-arm64 - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-arm64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim-arm64v8 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.debian-x64 b/samples/aspnetapp/Dockerfile.debian-x64 deleted file mode 100644 index 1f60e5cf75..0000000000 --- a/samples/aspnetapp/Dockerfile.debian-x64 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-x64 - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.debian-x64-slim b/samples/aspnetapp/Dockerfile.debian-x64-slim deleted file mode 100644 index 6a37a66801..0000000000 --- a/samples/aspnetapp/Dockerfile.debian-x64-slim +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-x64 /p:PublishReadyToRun=true - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-bullseye-slim-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.nanoserver b/samples/aspnetapp/Dockerfile.nanoserver new file mode 100644 index 0000000000..a5cd60efd9 --- /dev/null +++ b/samples/aspnetapp/Dockerfile.nanoserver @@ -0,0 +1,23 @@ +# escape=` +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +ARG TAG=ltsc2022 +FROM mcr.microsoft.com/dotnet/sdk:7.0-nanoserver-$TAG AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY aspnetapp/*.csproj . +RUN dotnet restore --use-current-runtime + +# copy everything else and build app +COPY aspnetapp/. . +RUN dotnet publish --use-current-runtime --no-restore -o /app + + +# final stage/image +FROM mcr.microsoft.com/dotnet/aspnet:7.0-nanoserver-$TAG +WORKDIR /app +COPY --from=build /app . +HEALTHCHECK CMD curl -sf --show-error http://localhost:80/healthz || exit 1 + +ENTRYPOINT ["aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.nanoserver-slim b/samples/aspnetapp/Dockerfile.nanoserver-slim index 019930fa6f..282c8d1b88 100644 --- a/samples/aspnetapp/Dockerfile.nanoserver-slim +++ b/samples/aspnetapp/Dockerfile.nanoserver-slim @@ -1,8 +1,8 @@ # escape=` - +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md ARG TAG=ltsc2022 -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:7.0-nanoserver-$TAG AS build WORKDIR /source # copy csproj and restore as distinct layers @@ -11,7 +11,8 @@ RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app --use-current-runtime --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true +RUN dotnet publish --use-current-runtime --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true + # final stage/image FROM mcr.microsoft.com/windows/nanoserver:$TAG diff --git a/samples/aspnetapp/Dockerfile.nanoserver-x64 b/samples/aspnetapp/Dockerfile.nanoserver-x64 deleted file mode 100644 index 5213ea4687..0000000000 --- a/samples/aspnetapp/Dockerfile.nanoserver-x64 +++ /dev/null @@ -1,19 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r win-x64 - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r win-x64 --self-contained false --no-restore - -# final stage/image -# Relies on 7.0 multi-arch tag to pick the same Windows version as the host. -# Alternatively, a release specific tag can be used, like: `7.0-nanoserver-ltsc2022` -FROM mcr.microsoft.com/dotnet/aspnet:7.0 -WORKDIR /app -COPY --from=build /app ./ -ENTRYPOINT ["aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.nanoserver-x64-slim b/samples/aspnetapp/Dockerfile.nanoserver-x64-slim deleted file mode 100644 index ab9180a7c7..0000000000 --- a/samples/aspnetapp/Dockerfile.nanoserver-x64-slim +++ /dev/null @@ -1,26 +0,0 @@ -# escape=` - -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r win-x64 /p:PublishReadyToRun=true - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r win-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 -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"] diff --git a/samples/aspnetapp/Dockerfile.ubuntu b/samples/aspnetapp/Dockerfile.ubuntu new file mode 100644 index 0000000000..bddb0cda83 --- /dev/null +++ b/samples/aspnetapp/Dockerfile.ubuntu @@ -0,0 +1,19 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY aspnetapp/*.csproj . +RUN dotnet restore --use-current-runtime + +# copy everything else and build app +COPY aspnetapp/. . +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + + +# final stage/image +FROM mcr.microsoft.com/dotnet/aspnet:7.0-jammy +WORKDIR /app +COPY --from=build /app . +ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.ubuntu-x64 b/samples/aspnetapp/Dockerfile.ubuntu-x64 deleted file mode 100644 index 83e75f6a8b..0000000000 --- a/samples/aspnetapp/Dockerfile.ubuntu-x64 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-x64 - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-jammy-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.ubuntu-x64-slim b/samples/aspnetapp/Dockerfile.ubuntu-x64-slim deleted file mode 100644 index dce297e275..0000000000 --- a/samples/aspnetapp/Dockerfile.ubuntu-x64-slim +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r linux-x64 /p:PublishReadyToRun=true - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-jammy-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.windowsservercore-x64 b/samples/aspnetapp/Dockerfile.windowsservercore similarity index 59% rename from samples/aspnetapp/Dockerfile.windowsservercore-x64 rename to samples/aspnetapp/Dockerfile.windowsservercore index 351831bcd3..fe923d915c 100644 --- a/samples/aspnetapp/Dockerfile.windowsservercore-x64 +++ b/samples/aspnetapp/Dockerfile.windowsservercore @@ -1,17 +1,19 @@ -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore -r win-x64 +RUN dotnet restore --use-current-runtime # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r win-x64 --self-contained false --no-restore +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:7.0-windowsservercore-ltsc2022 AS runtime WORKDIR /app COPY --from=build /app . +USER ContainerUser ENTRYPOINT ["aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.windowsservercore-containeruser b/samples/aspnetapp/Dockerfile.windowsservercore-containeruser deleted file mode 100644 index b5ff991f65..0000000000 --- a/samples/aspnetapp/Dockerfile.windowsservercore-containeruser +++ /dev/null @@ -1,21 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r win-x64 - -# copy everything else and build app -COPY 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:7.0-windowsservercore-ltsc2022 - -WORKDIR /app -COPY --from=build /app ./ - -USER ContainerUser -ENTRYPOINT ["aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.windowsservercore-iis-x64 b/samples/aspnetapp/Dockerfile.windowsservercore-iis similarity index 85% rename from samples/aspnetapp/Dockerfile.windowsservercore-iis-x64 rename to samples/aspnetapp/Dockerfile.windowsservercore-iis index c2d2015353..910ff54bb8 100644 --- a/samples/aspnetapp/Dockerfile.windowsservercore-iis-x64 +++ b/samples/aspnetapp/Dockerfile.windowsservercore-iis @@ -1,16 +1,16 @@ # escape=` - -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore -r win-x64 +RUN dotnet restore --use-current-runtime # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r win-x64 --self-contained false --no-restore +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app # final stage/image FROM mcr.microsoft.com/dotnet/aspnet:7.0-windowsservercore-ltsc2022 diff --git a/samples/aspnetapp/Dockerfile.windowsservercore-x64-slim b/samples/aspnetapp/Dockerfile.windowsservercore-x64-slim deleted file mode 100644 index 4a56d8e11d..0000000000 --- a/samples/aspnetapp/Dockerfile.windowsservercore-x64-slim +++ /dev/null @@ -1,26 +0,0 @@ -# escape=` - -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -r win-x64 /p:PublishReadyToRun=true - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -c Release -o /app -r win-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/windows/servercore:ltsc2022 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"] diff --git a/samples/complexapp/Dockerfile b/samples/complexapp/Dockerfile index 51ed24f4ef..b596d4de51 100644 --- a/samples/complexapp/Dockerfile +++ b/samples/complexapp/Dockerfile @@ -6,14 +6,14 @@ WORKDIR /source COPY complexapp/*.csproj complexapp/ COPY libfoo/*.csproj libfoo/ COPY libbar/*.csproj libbar/ -RUN dotnet restore complexapp/complexapp.csproj +RUN dotnet restore complexapp/complexapp.csproj --use-current-runtime # copy and build app and libraries COPY complexapp/ complexapp/ COPY libfoo/ libfoo/ COPY libbar/ libbar/ WORKDIR /source/complexapp -RUN dotnet build -c Release --no-restore +RUN dotnet build --use-current-runtime --no-restore # test stage -- exposes optional entrypoint # target entrypoint with: docker build --target test @@ -24,12 +24,12 @@ COPY tests/*.csproj . RUN dotnet restore tests.csproj COPY tests/ . -RUN dotnet build --no-restore +RUN dotnet build --use-current-runtime --no-restore ENTRYPOINT ["dotnet", "test", "--logger:trx", "--no-restore", "--no-build"] FROM build AS publish -RUN dotnet publish -c Release --no-build -o /app +RUN dotnet publish --use-current-runtime --no-build -o /app # final stage/image FROM mcr.microsoft.com/dotnet/runtime:7.0 diff --git a/samples/complexapp/complexapp/complexapp.csproj b/samples/complexapp/complexapp/complexapp.csproj index 24c3d68b03..f79f251656 100644 --- a/samples/complexapp/complexapp/complexapp.csproj +++ b/samples/complexapp/complexapp/complexapp.csproj @@ -4,6 +4,7 @@ Exe net7.0 enable + true diff --git a/samples/dotnetapp/Dockerfile b/samples/dotnetapp/Dockerfile index 2721a16354..c3ed9047d9 100644 --- a/samples/dotnetapp/Dockerfile +++ b/samples/dotnetapp/Dockerfile @@ -1,4 +1,5 @@ -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /source @@ -8,7 +9,8 @@ RUN dotnet restore --use-current-runtime # copy and publish app and libraries COPY . . -RUN dotnet publish -c Release -o /app --use-current-runtime --self-contained false --no-restore +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + # final stage/image FROM mcr.microsoft.com/dotnet/runtime:7.0 diff --git a/samples/dotnetapp/Dockerfile.alpine b/samples/dotnetapp/Dockerfile.alpine new file mode 100644 index 0000000000..d01f33df1b --- /dev/null +++ b/samples/dotnetapp/Dockerfile.alpine @@ -0,0 +1,21 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY *.csproj . +RUN dotnet restore --use-current-runtime + +# copy and publish app and libraries +COPY . . +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + + +# Enable globalization and time zones: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md +# final stage/image +FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine +WORKDIR /app +COPY --from=build /app . +ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.alpine-arm32 b/samples/dotnetapp/Dockerfile.alpine-arm32 deleted file mode 100644 index 5beed66f01..0000000000 --- a/samples/dotnetapp/Dockerfile.alpine-arm32 +++ /dev/null @@ -1,27 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-musl-arm - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-musl-arm --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine-arm32v7 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] - -# See: https://github.com/dotnet/announcements/issues/20 -# Uncomment to enable globalization APIs (or delete) -# ENV \ -# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ -# LC_ALL=en_US.UTF-8 \ -# LANG=en_US.UTF-8 -# RUN apk add --no-cache \ -# icu-data-full \ -# icu-libs diff --git a/samples/dotnetapp/Dockerfile.alpine-arm32-slim b/samples/dotnetapp/Dockerfile.alpine-arm32-slim deleted file mode 100644 index a019ff3c37..0000000000 --- a/samples/dotnetapp/Dockerfile.alpine-arm32-slim +++ /dev/null @@ -1,27 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-musl-arm /p:PublishReadyToRun=true - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-musl-arm --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-arm32v7 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] - -# See: https://github.com/dotnet/announcements/issues/20 -# Uncomment to enable globalization APIs (or delete) -# ENV \ -# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ -# LC_ALL=en_US.UTF-8 \ -# LANG=en_US.UTF-8 -# RUN apk add --no-cache \ -# icu-data-full \ -# icu-libs diff --git a/samples/dotnetapp/Dockerfile.alpine-arm64 b/samples/dotnetapp/Dockerfile.alpine-arm64 deleted file mode 100644 index 8d840100b4..0000000000 --- a/samples/dotnetapp/Dockerfile.alpine-arm64 +++ /dev/null @@ -1,27 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-musl-arm64 - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-musl-arm64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine-arm64v8 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] - -# See: https://github.com/dotnet/announcements/issues/20 -# Uncomment to enable globalization APIs (or delete) -# ENV \ -# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ -# LC_ALL=en_US.UTF-8 \ -# LANG=en_US.UTF-8 -# RUN apk add --no-cache \ -# icu-data-full \ -# icu-libs diff --git a/samples/dotnetapp/Dockerfile.alpine-arm64-slim b/samples/dotnetapp/Dockerfile.alpine-arm64-slim deleted file mode 100644 index 06d852db19..0000000000 --- a/samples/dotnetapp/Dockerfile.alpine-arm64-slim +++ /dev/null @@ -1,27 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-musl-arm64 /p:PublishReadyToRun=true - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-musl-arm64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-arm64v8 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] - -# See: https://github.com/dotnet/announcements/issues/20 -# Uncomment to enable globalization APIs (or delete) -# ENV \ -# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ -# LC_ALL=en_US.UTF-8 \ -# LANG=en_US.UTF-8 -# RUN apk add --no-cache \ -# icu-data-full \ -# icu-libs diff --git a/samples/dotnetapp/Dockerfile.alpine-slim b/samples/dotnetapp/Dockerfile.alpine-slim new file mode 100644 index 0000000000..718116d063 --- /dev/null +++ b/samples/dotnetapp/Dockerfile.alpine-slim @@ -0,0 +1,21 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY *.csproj . +RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true + +# copy and publish app and libraries +COPY . . +RUN dotnet publish --use-current-runtime --self-contained true --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true + + +# Enable globalization and time zones: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md +# final stage/image +FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine +WORKDIR /app +COPY --from=build /app . +ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.alpine-x64 b/samples/dotnetapp/Dockerfile.alpine-x64 deleted file mode 100644 index f9652c984d..0000000000 --- a/samples/dotnetapp/Dockerfile.alpine-x64 +++ /dev/null @@ -1,27 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-musl-x64 - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-musl-x64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] - -# See: https://github.com/dotnet/announcements/issues/20 -# Uncomment to enable globalization APIs (or delete) -# ENV \ -# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ -# LC_ALL=en_US.UTF-8 \ -# LANG=en_US.UTF-8 -# RUN apk add --no-cache \ -# icu-data-full \ -# icu-libs diff --git a/samples/dotnetapp/Dockerfile.alpine-x64-slim b/samples/dotnetapp/Dockerfile.alpine-x64-slim deleted file mode 100644 index 1ed0ef989b..0000000000 --- a/samples/dotnetapp/Dockerfile.alpine-x64-slim +++ /dev/null @@ -1,27 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-musl-x64 /p:PublishReadyToRun=true - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] - -# See: https://github.com/dotnet/announcements/issues/20 -# Uncomment to enable globalization APIs (or delete) -# ENV \ -# DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ -# LC_ALL=en_US.UTF-8 \ -# LANG=en_US.UTF-8 -# RUN apk add --no-cache \ -# icu-data-full \ -# icu-libs diff --git a/samples/dotnetapp/Dockerfile.chiseled b/samples/dotnetapp/Dockerfile.chiseled index c0b3336dc2..b656e86392 100644 --- a/samples/dotnetapp/Dockerfile.chiseled +++ b/samples/dotnetapp/Dockerfile.chiseled @@ -1,4 +1,5 @@ -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build WORKDIR /source @@ -8,7 +9,8 @@ RUN dotnet restore --use-current-runtime # copy and publish app and libraries COPY . . -RUN dotnet publish -c Release -o /app --use-current-runtime --self-contained false --no-restore +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + # final stage/image FROM mcr.microsoft.com/dotnet/nightly/runtime:7.0-jammy-chiseled diff --git a/samples/dotnetapp/Dockerfile.debian-arm32 b/samples/dotnetapp/Dockerfile.debian-arm32 deleted file mode 100644 index 4511075654..0000000000 --- a/samples/dotnetapp/Dockerfile.debian-arm32 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-arm - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-arm --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-bullseye-slim-arm32v7 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.debian-arm64 b/samples/dotnetapp/Dockerfile.debian-arm64 deleted file mode 100644 index 50828444b4..0000000000 --- a/samples/dotnetapp/Dockerfile.debian-arm64 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-arm64 - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-arm64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-bullseye-slim-arm64v8 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.debian-x64 b/samples/dotnetapp/Dockerfile.debian-x64 deleted file mode 100644 index f1d5dd608e..0000000000 --- a/samples/dotnetapp/Dockerfile.debian-x64 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-x64 - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-bullseye-slim-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.debian-x64-slim b/samples/dotnetapp/Dockerfile.debian-x64-slim deleted file mode 100644 index a0c4cd3818..0000000000 --- a/samples/dotnetapp/Dockerfile.debian-x64-slim +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-x64 /p:PublishReadyToRun=true - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-bullseye-slim-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.nanoserver-x64 b/samples/dotnetapp/Dockerfile.nanoserver similarity index 52% rename from samples/dotnetapp/Dockerfile.nanoserver-x64 rename to samples/dotnetapp/Dockerfile.nanoserver index 69c8a1a65d..0c9b2843e5 100644 --- a/samples/dotnetapp/Dockerfile.nanoserver-x64 +++ b/samples/dotnetapp/Dockerfile.nanoserver @@ -1,5 +1,8 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +# escape=` +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +ARG TAG=ltsc2022 +FROM mcr.microsoft.com/dotnet/sdk:7.0-nanoserver-$TAG AS build WORKDIR /source # copy csproj and restore as distinct layers @@ -11,9 +14,7 @@ COPY . . RUN dotnet publish -c Release -o /app -r win-x64 --self-contained false --no-restore # final stage/image -# Relies on 7.0 multi-arch tag to pick the same Windows version as the host. -# Alternatively, a release specific tag can be used, like: `7.0-nanoserver-ltsc2022` -FROM mcr.microsoft.com/dotnet/runtime:7.0 +FROM mcr.microsoft.com/dotnet/runtime:7.0-nanoserver-$TAG WORKDIR /app COPY --from=build /app . ENTRYPOINT ["dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.nanoserver-slim b/samples/dotnetapp/Dockerfile.nanoserver-slim new file mode 100644 index 0000000000..d558990558 --- /dev/null +++ b/samples/dotnetapp/Dockerfile.nanoserver-slim @@ -0,0 +1,24 @@ +# escape=` +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +ARG TAG=ltsc2022 +FROM mcr.microsoft.com/dotnet/sdk:7.0-nanoserver-$TAG AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY *.csproj . +RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true + +# copy and publish app and libraries +COPY . . +RUN dotnet publish --use-current-runtime --self-contained true --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true + +# final stage/image +FROM mcr.microsoft.com/windows/nanoserver:$TAG +WORKDIR /app +COPY --from=build /app . + +# Enable detection of running in a container +ENV DOTNET_RUNNING_IN_CONTAINER=true + +ENTRYPOINT ["dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.nanoserver-x64-slim b/samples/dotnetapp/Dockerfile.nanoserver-x64-slim deleted file mode 100644 index 03887d4159..0000000000 --- a/samples/dotnetapp/Dockerfile.nanoserver-x64-slim +++ /dev/null @@ -1,21 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r win-x64 /p:PublishReadyToRun=true - -# 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 /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 -WORKDIR /app -COPY --from=build /app . - -# Enable detection of running in a container -ENV DOTNET_RUNNING_IN_CONTAINER=true - -ENTRYPOINT ["dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.ubuntu b/samples/dotnetapp/Dockerfile.ubuntu new file mode 100644 index 0000000000..a19e89f373 --- /dev/null +++ b/samples/dotnetapp/Dockerfile.ubuntu @@ -0,0 +1,19 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY *.csproj . +RUN dotnet restore --use-current-runtime + +# copy and publish app and libraries +COPY . . +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + + +# final stage/image +FROM mcr.microsoft.com/dotnet/runtime:7.0-jammy +WORKDIR /app +COPY --from=build /app . +ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.ubuntu-arm32 b/samples/dotnetapp/Dockerfile.ubuntu-arm32 deleted file mode 100644 index ad55314747..0000000000 --- a/samples/dotnetapp/Dockerfile.ubuntu-arm32 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-arm - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-arm --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-jammy-arm32v7 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.ubuntu-arm64 b/samples/dotnetapp/Dockerfile.ubuntu-arm64 deleted file mode 100644 index ecad79e405..0000000000 --- a/samples/dotnetapp/Dockerfile.ubuntu-arm64 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-arm64 - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-arm64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-jammy-arm64v8 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.ubuntu-x64 b/samples/dotnetapp/Dockerfile.ubuntu-x64 deleted file mode 100644 index 2413234077..0000000000 --- a/samples/dotnetapp/Dockerfile.ubuntu-x64 +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-x64 - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained false --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-jammy-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.ubuntu-x64-slim b/samples/dotnetapp/Dockerfile.ubuntu-x64-slim deleted file mode 100644 index f886d2c2ef..0000000000 --- a/samples/dotnetapp/Dockerfile.ubuntu-x64-slim +++ /dev/null @@ -1,17 +0,0 @@ -# https://hub.docker.com/_/microsoft-dotnet -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore -r linux-x64 /p:PublishReadyToRun=true - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-jammy-amd64 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.windowsservercore-x64 b/samples/dotnetapp/Dockerfile.windowsservercore-x64 index 878f145a56..64f55f1166 100644 --- a/samples/dotnetapp/Dockerfile.windowsservercore-x64 +++ b/samples/dotnetapp/Dockerfile.windowsservercore-x64 @@ -1,4 +1,5 @@ -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build WORKDIR /source diff --git a/samples/dotnetapp/Dockerfile.windowsservercore-x64-slim b/samples/dotnetapp/Dockerfile.windowsservercore-x64-slim index 1c62932836..b6cb7f72a8 100644 --- a/samples/dotnetapp/Dockerfile.windowsservercore-x64-slim +++ b/samples/dotnetapp/Dockerfile.windowsservercore-x64-slim @@ -1,14 +1,15 @@ -# https://hub.docker.com/_/microsoft-dotnet +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore -r win-x64 /p:PublishReadyToRun=true +RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true # 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 /p:PublishSingleFile=true +RUN dotnet publish --use-current-runtime --self-contained true --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true # final stage/image FROM mcr.microsoft.com/windows/servercore:ltsc2022 diff --git a/samples/dotnetapp/dotnetapp.csproj b/samples/dotnetapp/dotnetapp.csproj index 25f60096ed..aa077a0f83 100644 --- a/samples/dotnetapp/dotnetapp.csproj +++ b/samples/dotnetapp/dotnetapp.csproj @@ -4,6 +4,7 @@ Exe net7.0 enable + true diff --git a/samples/globalapp/Dockerfile b/samples/globalapp/Dockerfile index 65a88544c2..39c8f621f5 100644 --- a/samples/globalapp/Dockerfile +++ b/samples/globalapp/Dockerfile @@ -10,7 +10,7 @@ RUN dotnet restore --use-current-runtime # copy and publish app and libraries COPY . . -RUN dotnet publish -c Release -o /app --use-current-runtime --self-contained false --no-restore +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app # final stage/image FROM mcr.microsoft.com/dotnet/runtime:$TAG From 25adb96baef9a32ae35a9bf0eb33c490b36786d3 Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Sat, 1 Apr 2023 10:15:37 -0700 Subject: [PATCH 03/11] Update READMEs --- samples/README.md | 34 +-- samples/aspnetapp/Dockerfile.debian | 19 ++ samples/aspnetapp/README.md | 250 ++---------------- samples/complexapp/libbar/libbar.csproj | 2 +- samples/complexapp/libfoo/libfoo.csproj | 2 +- samples/dotnetapp/Dockerfile.alpine-icu | 30 +++ samples/dotnetapp/Dockerfile.debian | 20 ++ ...rcore-x64 => Dockerfile.windowsservercore} | 4 +- .../Dockerfile.windowsservercore-x64-slim | 22 -- samples/dotnetapp/README.md | 209 ++------------- samples/globalapp/README.md | 22 +- 11 files changed, 160 insertions(+), 454 deletions(-) create mode 100644 samples/aspnetapp/Dockerfile.debian create mode 100644 samples/dotnetapp/Dockerfile.alpine-icu create mode 100644 samples/dotnetapp/Dockerfile.debian rename samples/dotnetapp/{Dockerfile.windowsservercore-x64 => Dockerfile.windowsservercore} (78%) delete mode 100644 samples/dotnetapp/Dockerfile.windowsservercore-x64-slim diff --git a/samples/README.md b/samples/README.md index b40fff3cb7..2edc29373b 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,36 +1,40 @@ -# .NET Docker samples +# .NET container samples -The following samples and guidance demonstrate how to use .NET and Docker for development, testing and production. You can use the samples as the basis of your own Docker images or just to learn. +The following samples and guidance demonstrate how to use .NET and Docker for development, testing and production. You can equally use the samples for learning about containers or as the basis of your own container images. ## Building images -* [Build a .NET Docker image](dotnetapp/README.md) -* [Build an ASP.NET Core Docker image](aspnetapp/README.md) -* [Build and test a multi-project solution](complexapp/README.md) -* [Building a globalization aware (or unaware) image](globalapp/README.md) +* [Build a .NET container image](dotnetapp/README.md) +* [Build an ASP.NET Core container image](aspnetapp/README.md) +* [Building a globalization and time zone aware (or unaware) image](globalapp/README.md) +* [Container best practices](container-best-practices.md) * [Build for a platform](build-for-a-platform.md) -* [Enable (or disable) globalization](enable-globalization.md) ## Development guidance -* [Establishing a Docker environment](establishing-docker-environment.md) -* [Selecting .NET image tags](selecting-tags.md) +* [Selecting .NET image tags](../documentation/supported-tags.md) +* [Enable (or disable) globalization](enable-globalization.md) +* [Build and test a multi-project solution](complexapp/README.md) * [Run test in a container](run-tests-in-sdk-container.md) * [Build in an SDK container](build-in-sdk-container.md) * [Run applications in an SDK container](run-in-sdk-container.md) -* [Run ASP.NET Core Applications in development with Docker and HTTPS](run-aspnetcore-https-development.md) +* [Run ASP.NET Core Applications in development with container and HTTPS](run-aspnetcore-https-development.md) * [Discover licensing for Linux image contents](https://github.com/dotnet/dotnet-docker/blob/main/documentation/image-artifact-details.md) ## Hosting guidance -* [Host ASP.NET Core Images with Docker and HTTPS](host-aspnetcore-https.md) -* [Push Docker Images to Azure Container Registry](push-image-to-acr.md) -* [Push Docker Images to Docker Hub](push-image-to-dockerhub.md) +* [Host ASP.NET Core Images with container and HTTPS](host-aspnetcore-https.md) +* [Push container Images to Azure Container Registry](push-image-to-acr.md) +* [Push container Images to Docker Hub](push-image-to-dockerhub.md) * [Deploy ASP.NET Core Applications to Azure Container Instances](deploy-container-to-aci.md) -## Scenario guidance +## Other documentation -You can find tips and tricks, best practices, and samples of commonly used technology in the [.NET Docker scenarios documentation](../documentation/scenarios/README.md). +* [Introduction to .NET and Docker](https://learn.microsoft.com/dotnet/core/docker/)] +* [Announcing built-in container support for the .NET SDK](https://devblogs.microsoft.com/dotnet/announcing-builtin-container-support-for-the-dotnet-sdk/) +* [Staying safe in containers](https://devblogs.microsoft.com/dotnet/staying-safe-with-dotnet-containers/) +* [Improving multi-platform container support](https://devblogs.microsoft.com/dotnet/improving-multiplatform-container-support/) +* [Container blog posts](https://devblogs.microsoft.com/dotnet/category/containers/) ## Try pre-built images diff --git a/samples/aspnetapp/Dockerfile.debian b/samples/aspnetapp/Dockerfile.debian new file mode 100644 index 0000000000..82976e76ac --- /dev/null +++ b/samples/aspnetapp/Dockerfile.debian @@ -0,0 +1,19 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY aspnetapp/*.csproj . +RUN dotnet restore --use-current-runtime + +# copy everything else and build app +COPY aspnetapp/. . +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + + +# final stage/image +FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim +WORKDIR /app +COPY --from=build /app . +ENTRYPOINT ["./aspnetapp.dll"] diff --git a/samples/aspnetapp/README.md b/samples/aspnetapp/README.md index e043c27a7a..09956d4f0e 100644 --- a/samples/aspnetapp/README.md +++ b/samples/aspnetapp/README.md @@ -1,14 +1,10 @@ # ASP.NET Core Docker Sample -This sample demonstrates how to build container images for ASP.NET Core web apps. You can use these samples for Linux and Windows containers, for x64, ARM32 and ARM64 architectures. - -The sample builds an application in a [.NET SDK container](https://hub.docker.com/_/microsoft-dotnet-sdk/) and then copies the build result into a new image (the one you are building) based on the smaller [.NET Docker Runtime image](https://hub.docker.com/_/microsoft-dotnet-runtime/). You can test the built image locally or deploy it to a [container registry](../push-image-to-acr.md). - -The instructions assume that you have cloned this repo, have [Docker](https://www.docker.com/products/docker) installed, and have a command prompt open within the `samples/aspnetapp` directory within the repo. +This sample demonstrates how to build container images for ASP.NET Core web apps. See [.NET Docker Samples](../README.md) for more samples. ## Try a pre-built version of the sample -If you want to skip ahead, you can try a pre-built version with the following command and access it in your web browser at `http://localhost:8000`. +You can start by launching a sample from our [container registry](https://mcr.microsoft.com/) and access it in your web browser at `http://localhost:8000`. ```console docker run --rm -it -p 8000:80 mcr.microsoft.com/dotnet/samples:aspnetapp @@ -21,19 +17,9 @@ $ curl http://localhost:8000/Environment {"runtimeVersion":".NET 7.0.2","osVersion":"Linux 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTC 2022","osArchitecture":"X64","user":"root","processorCount":16,"totalAvailableMemoryBytes":67430023168,"memoryLimit":9223372036854771712,"memoryUsage":100577280} ``` -You can see the app running via `docker ps`. - -```bash -$ docker ps -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -d79edc6bfcb6 mcr.microsoft.com/dotnet/samples:aspnetapp "./aspnetapp" 35 seconds ago Up 34 seconds (healthy) 0.0.0.0:8080->80/tcp nice_curran -``` - -You may notice that the sample includes a [health check](https://docs.docker.com/engine/reference/builder/#healthcheck), which is indicated in the "STATUS" column. - ## Build an ASP.NET Core image -You can build and run an image using the following instructions: +You can build and run an image using the following instructions (if you've cloned this repo): ```console docker build --pull -t aspnetapp . @@ -50,227 +36,47 @@ Now listening on: http://[::]:80 Application started. Press Ctrl+C to shut down. ``` -> Note: The `-p` argument maps port 8000 on your local machine to port 80 in the container (the form of the port mapping is `host:container`). See the [Docker run reference](https://docs.docker.com/engine/reference/commandline/run/) for more information on command-line parameters. In some cases, you might see an error because the host port you select is already in use. Choose a different port in that case. - -After the application starts, navigate to `http://localhost:8000` in your web browser. +After the application starts, navigate to `http://localhost:8000` in your web browser. You can also view the ASP.NET Core site running in the container from another machine with a local IP address such as `http://192.168.1.18:8000`. -You can also view the ASP.NET Core site running in the container on another machine. This is particularly useful if you are wanting to view an application running on an ARM device like a Raspberry Pi on your network. In that scenario, you might view the site at a local IP address such as `http://192.168.1.18:8000`. +> Note: ASP.NET Core apps (in our official images) listen to [port 80 by default](https://github.com/dotnet/dotnet-docker/blob/d5df3f0710c43b14aacdac1e30ceed666699ea69/src/runtime-deps/6.0/jammy/amd64/Dockerfile#L19). The [`-p` argument](https://docs.docker.com/engine/reference/commandline/run/#publish) in these examples maps host port `8000` to container port `80` (`host:container` mapping). The container will not be accessible without this mapping. ASP.NET Core can be [configured to listen on a different or additional port](https://learn.microsoft.com/aspnet/core/fundamentals/servers/kestrel/endpoints). -In production, you will typically start your container with `docker run -d`. This argument starts the container as a service, without any console interaction. You then interact with it through other Docker commands or APIs exposed by the containerized application. - -We recommend that you do not use `--rm` in production. It cleans up container resources, preventing you from collecting logs that may have been captured in a container that has either stopped or crashed. - -Notes: - -- See [Establishing docker environment](../establishing-docker-environment.md) for more information on correctly configuring Dockerfiles and `docker build` commands. -- See [Building for a platform](../build-for-a-platform.md) for instructions on how to target specific platforms. -- See [Enable globalization](../enable-globalization.md) for instructions on how to install system globalization libraries. - -## Build an image with `HEALTHCHECK` - -The sample uses [ASP.NET Core Health Check middleware](https://learn.microsoft.com/aspnet/core/host-and-deploy/health-checks). You can direct Docker, Kubernetes, or other systems to use the ASP.NET Core `healthz` endpoint. - -The [`HEALTHCHECK`](https://docs.docker.com/engine/reference/builder/#healthcheck) directive is implemented in the [`Dockerfile.alpine-slim`](Dockerfile.alpine-slim) and [`Dockerfile.nanoserver`](Dockerfile.nanoserver-slim). You can build those via the same pattern. - -```bash -$ docker build --pull -t aspnetapp -f Dockerfile.alpine-slim . -$ docker run --rm -it -p 8000:80 aspnetapp -``` - -In another terminal: +You can see the app running via `docker ps`. ```bash $ docker ps -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -b143cf4ac0d1 aspnetapp "./aspnetapp" 8 seconds ago Up 7 seconds (health: starting) 0.0.0.0:8000->80/tcp fervent_lichterman -``` - -After 30s, the status should transition to "healthy" from "health: starting". - -You can also look at health status with `docker inspect`. The following pattern uses `jq`, which makes it much easier to drill in on the interesting data. - -```bash -$ docker inspect b143cf4ac0d1 | jq .[-1].State.Health -{ - "Status": "healthy", - "FailingStreak": 0, - "Log": [ - { - "Start": "2023-01-26T23:39:06.424631566Z", - "End": "2023-01-26T23:39:06.589344994Z", - "ExitCode": 0, - "Output": "Healthy" - }, - { - "Start": "2023-01-26T23:39:36.597795818Z", - "End": "2023-01-26T23:39:36.70857373Z", - "ExitCode": 0, - "Output": "Healthy" - } - ] -} -``` - -The same thing can be accomplished with PowerShell. - -```powershell -> $healthLog = docker inspect 92648775bce8 | ConvertFrom-Json -> $healthLog[0].State.Health.Log - -Start End ExitCode Output ------ --- -------- ------ -2023-01-28T10:14:54.589686-08:00 2023-01-28T10:14:54.6137922-08:00 0 Healthy -2023-01-28T10:15:24.6264335-08:00 2023-01-28T10:15:24.6602762-08:00 0 Healthy -2023-01-28T10:15:54.6766598-08:00 2023-01-28T10:15:54.703489-08:00 0 Healthy -2023-01-28T10:16:24.7192354-08:00 2023-01-28T10:16:24.74409-08:00 0 Healthy -2023-01-28T10:16:54.7499988-08:00 2023-01-28T10:16:54.7750448-08:00 0 Healthy -``` - -## Build non-root images - -.NET 8 images include a non-root user, `app`. You can use the `USER` instruction to set this user and then your images will be non-root. - -The following Dockerfiles demonstrate the non-root use case: - -- [Dockerfile.alpine-non-root](Dockerfile.alpine-non-root) -- [Dockerfile.windowsservercore-containeruser](Dockerfile.windowsservercore-containeruser) - -Note: The Windows example uses the existing `ContainerUser` user, so also works with prior .NET versions. - -## Build an image for Alpine, Debian or Ubuntu - -.NET multi-platform tags result in Debian-based images, for Linux. For example, you will pull a Debian-based image if you use a simple version-based tag, such as `6.0`, as opposed to a distro-specific tag like `6.0-alpine`. - -This sample includes Dockerfile examples that explicitly target Alpine, Debian and Ubuntu. The [.NET Docker Sample](../dotnetapp/README.md) demonstrates targeting a larger set of distros. - -The following example demonstrates targeting distros explicitly and also shows the size differences between the distros. Tags are added to the image name to differentiate the images. - -On Linux: - -```console -docker build --pull -t aspnetapp:alpine -f Dockerfile.alpine-x64 . -docker run --rm -it -p 8000:80 aspnetapp:alpine -``` - -You can view in the app in your browser in the same way as demonstrated earlier. - -You can also build for Debian and Ubuntu: - -```console -docker build --pull -t aspnetapp:debian -f Dockerfile.debian-x64 . -docker build --pull -t aspnetapp:ubuntu -f Dockerfile.ubuntu-x64 . -``` - -You can use `docker images` to see the images you've built and to compare file sizes: - -```console -% docker images aspnetapp -REPOSITORY TAG IMAGE ID CREATED SIZE -aspnetapp ubuntu 0f5bc72e4caf 14 seconds ago 209MB -aspnetapp debian f70387d4d802 35 seconds ago 212MB -aspnetapp alpine 6da2c287c42c 10 hours ago 109MB -aspnetapp latest 8c5d1952e3b7 10 hours ago 212MB -``` - -You can run these images in the same way as is done above, with Alpine. - -## Build an image for Windows Nano Server - -The following example demonstrates targeting Windows Nano Server (x64) explicitly (you must have [Windows containers enabled](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers)): - -```console -docker build --pull -t aspnetapp:nanoserver -f Dockerfile.nanoserver-x64 . -docker run --rm -it -p 8000:80 aspnetapp:nanoserver -``` - -You can view in the app in your browser in the same way as demonstrated earlier. - -You can use `docker images` to see the images you've built: - -```console -> docker images aspnetapp -REPOSITORY TAG IMAGE ID CREATED SIZE -aspnetapp latest b2f0ecb7bdf9 About an hour ago 353MB -aspnetapp nanoserver d4b7586827f2 About an hour ago 353MB -``` - -## Build an image for Windows Server Core - -The instructions for Windows Server Core are very similar to Windows Nano Server. There are three different sample Dockerfile files provided for Windows Server Core, which can all be used with the same approach as the Nano Server ones. - -In addition, one of the samples enables using IIS as the Web Server instead of Kestrel. The following example demonstrates using that Dockerfile. - -```console -docker build -t aspnetapp -f .\Dockerfile.windowsservercore-iis-x64 . -docker run --rm -it -p:8080:80 aspnetapp +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +d79edc6bfcb6 mcr.microsoft.com/dotnet/samples:aspnetapp "./aspnetapp" 35 seconds ago Up 34 seconds (healthy) 0.0.0.0:8080->80/tcp nice_curran ``` -## Optimizing for startup performance - -You can improve startup performance by using [Ready to Run (R2R) compilation](https://github.com/dotnet/runtime/blob/master/docs/design/coreclr/botr/readytorun-overview.md) for your application. You can do this by setting the `PublishReadyToRun` property, which will take effect when you publish an application. This is what the `-slim` samples do (they are explained shortly). - -You can add the `PublishReadyToRun` property in two ways: - -- Set it in your project file, as: `true` -- Set it on the command line, as: `/p:PublishReadyToRun=true` - -The default `Dockerfile` that comes with the sample doesn't use R2R compilation because the application is too small to warrant it. The bulk of the IL code that is executed in this sample application is within the .NET libraries, which are already R2R-compiled. +You may notice that the sample includes a [health check](../enable-healthchecks.md), indicated in the "STATUS" column. -## Optimizing for size +## Supported Linux distros -You may want to build an ASP.NET Core image that is optimized for size by publishing an application that includes the ASP.NET Core runtime (self-contained) and then is trimmed with the assembly-linker. These are the tools offered in the .NET SDK for producing the smallest images. This approach may be preferred if you are running a single .NET app on a machine. Otherwise, building images on the ASP.NET Core runtime layer is recommended and likely preferred. +The .NET Team publishes images for [multiple distros](../../documentation/supported-platforms.md.md). -The following instructions are for x64 only, but can be straightforwardly updated for use with ARM architectures. +Samples are provided for: -There are a set of '-slim' Dockerfiles included with this sample that are opted into the following [.NET SDK publish operations](https://docs.microsoft.com/dotnet/core/deploying/): +- [Alpine](Dockerfile.alpine) +- [Debian](Dockerfile.debian) +- [Ubuntu](Dockerfile.ubuntu) +- [Ubuntu Chiseled](Dockerfile.chiseled) -* **Self-contained deployment** -- Publish the runtime with the application. -* **Assembly linking** -- Trim assemblies, including in the .NET framework, to make the application smaller. -* **Ready to Run (R2R) compilation** -- Compile assemblies to R2R format to make startup faster. R2R-compiled assemblies are larger. The benefit of R2R compilation for your application may be outweighed by the size increase, so please do test your application with and without R2R. +The default [Dockerfile](Dockerfile) uses a major.minor version tag, which references a multi-platform image that provides Debian and Windows Nano Server images (depending on the requesting client). -You are encouraged to experiment with these options if you want to see which combination of settings works best for you. +More extensive samples are provided for Alpine: -The following instructions demonstrate how to build the `slim` Dockerfiles: +- [Alpine with ICU (for globalization)](Dockerfile.alpine-icu) +- [Alpine with trimming, ready-to-run compilation, and self-contained publishing](Dockerfile.alpine-slim) -```console -docker build --pull -t aspnetapp:debian-slim -f Dockerfile.debian-x64-slim . -docker build --pull -t aspnetapp:alpine-slim -f Dockerfile.alpine-x64-slim . -``` - -You can then compare sizes between using a shared layer and optimizing for size using the `docker images` command again. The command below uses `grep`. `findstr` on Windows works equally well. - -```console -% docker images aspnetapp | grep alpine -aspnetapp alpine-slim 34135d057c0f 2 hours ago 97.7MB -aspnetapp alpine 8567c3d23608 2 hours ago 109MB -``` +These patterns can be applied to other distros. -Same thing with Debian: +## Supported Windows versions -```console -$ docker images aspnetapp | grep debian -aspnetapp debian edfd63050f14 11 seconds ago 212MB -aspnetapp debian-slim 13c30001b4fb 10 minutes ago 202MB -``` - -> Note: These image sizes are all uncompressed, on-disk sizes. When you pull an image from a registry, it is compressed, such that the size will be significantly smaller. See [Retrieving Docker Image Sizes](https://gist.github.com/MichaelSimons/fb588539dcefd9b5fdf45ba04c302db6) for more information. - -You can do the same thing with Windows Nano Server, as follows: - -```console -docker build --pull -t aspnetapp:nanoserver-slim -f Dockerfile.nanoserver-x64-slim . -``` - -And `docker images` will show you the Nano Server image you've just built. - -```console ->docker images aspnetapp -REPOSITORY TAG IMAGE ID CREATED SIZE -aspnetapp nanoserver-slim 59d9aa2e5826 11 seconds ago 341MB -aspnetapp nanoserver 1e16a73b42b3 34 seconds ago 353MB -``` +The .NET Team publishes images for [multiple Windows versions](../../documentation/supported-platforms.md.md). You must have [Windows containers enabled](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers) to use these images. -## More Samples +Samples are provided for -* [.NET Docker Samples](../README.md) -* [.NET Framework Docker Samples](https://github.com/microsoft/dotnet-framework-docker/blob/main/samples/README.md) +- [Nano Server](Dockerfile.nanoserver) +- [Nano Server with trimming, ready-to-run compilation, and self-contained publishing](Dockerfile.nanoserver-slim) +- [Windows Server Core](Dockerfile.windowsservercore) +- [Windows Server Core with IIS](Dockerfile.windowsservercore-iis) diff --git a/samples/complexapp/libbar/libbar.csproj b/samples/complexapp/libbar/libbar.csproj index 72764a6641..c01993fa72 100644 --- a/samples/complexapp/libbar/libbar.csproj +++ b/samples/complexapp/libbar/libbar.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net7.0 diff --git a/samples/complexapp/libfoo/libfoo.csproj b/samples/complexapp/libfoo/libfoo.csproj index 72764a6641..c01993fa72 100644 --- a/samples/complexapp/libfoo/libfoo.csproj +++ b/samples/complexapp/libfoo/libfoo.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net7.0 diff --git a/samples/dotnetapp/Dockerfile.alpine-icu b/samples/dotnetapp/Dockerfile.alpine-icu new file mode 100644 index 0000000000..6c5f5f293b --- /dev/null +++ b/samples/dotnetapp/Dockerfile.alpine-icu @@ -0,0 +1,30 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY *.csproj . +RUN dotnet restore --use-current-runtime + +# copy and publish app and libraries +COPY . . +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + + +# Enable globalization and time zones: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md +# final stage/image +FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine + +ENV \ + DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ + LC_ALL=en_US.UTF-8 \ + LANG=en_US.UTF-8 +RUN apk add --no-cache \ + icu-data-full \ + icu-libs + +WORKDIR /app +COPY --from=build /app . +ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.debian b/samples/dotnetapp/Dockerfile.debian new file mode 100644 index 0000000000..845bbbc327 --- /dev/null +++ b/samples/dotnetapp/Dockerfile.debian @@ -0,0 +1,20 @@ +# Learn about building .NET container images: +# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md +FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build +ARG TARGETARCH +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY *.csproj . +RUN dotnet restore --use-current-runtime + +# copy and publish app and libraries +COPY . . +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app + + +# final stage/image +FROM mcr.microsoft.com/dotnet/runtime:7.0-bullseye-slim +WORKDIR /app +COPY --from=build /app . +ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.windowsservercore-x64 b/samples/dotnetapp/Dockerfile.windowsservercore similarity index 78% rename from samples/dotnetapp/Dockerfile.windowsservercore-x64 rename to samples/dotnetapp/Dockerfile.windowsservercore index 64f55f1166..26c33318ca 100644 --- a/samples/dotnetapp/Dockerfile.windowsservercore-x64 +++ b/samples/dotnetapp/Dockerfile.windowsservercore @@ -5,11 +5,11 @@ WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore -r win-x64 +RUN dotnet restore --use-current-runtime # copy and publish app and libraries COPY . . -RUN dotnet publish -c Release -o /app -r win-x64 --self-contained false --no-restore +RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app # final stage/image FROM mcr.microsoft.com/dotnet/runtime:7.0-windowsservercore-ltsc2022 diff --git a/samples/dotnetapp/Dockerfile.windowsservercore-x64-slim b/samples/dotnetapp/Dockerfile.windowsservercore-x64-slim deleted file mode 100644 index b6cb7f72a8..0000000000 --- a/samples/dotnetapp/Dockerfile.windowsservercore-x64-slim +++ /dev/null @@ -1,22 +0,0 @@ -# Learn about building .NET container images: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true - -# copy and publish app and libraries -COPY . . -RUN dotnet publish --use-current-runtime --self-contained true --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true - -# final stage/image -FROM mcr.microsoft.com/windows/servercore:ltsc2022 -WORKDIR /app -COPY --from=build /app . - -# Enable detection of running in a container -ENV DOTNET_RUNNING_IN_CONTAINER=true - -ENTRYPOINT ["dotnetapp"] diff --git a/samples/dotnetapp/README.md b/samples/dotnetapp/README.md index 44b4e0706f..fd47d79f95 100644 --- a/samples/dotnetapp/README.md +++ b/samples/dotnetapp/README.md @@ -1,14 +1,10 @@ # .NET Docker Sample -This sample demonstrates how to build container images for .NET console apps. You can use this samples for Linux and Windows containers, for x64, ARM32 and ARM64 architectures. - -The sample builds an application in a [.NET SDK container](https://hub.docker.com/_/microsoft-dotnet-sdk/) and then copies the build result into a new image (the one you are building) based on the smaller [.NET Docker Runtime image](https://hub.docker.com/_/microsoft-dotnet-runtime/). You can test the built image locally or deploy it to a [container registry](../push-image-to-acr.md). - -The instructions assume that you have cloned this repo, have [Docker](https://www.docker.com/products/docker) installed, and have a command prompt open within the `samples/dotnetapp` directory within the repo. +This sample demonstrates how to build container images for .NET console apps. See [.NET Docker Samples](../README.md) for more samples. ## Try a pre-built version of the sample -If want to skip ahead, you can try a pre-built version with the following command: +You can start by launching a sample from our [container registry](https://mcr.microsoft.com/). ```console docker run --rm mcr.microsoft.com/dotnet/samples @@ -16,202 +12,41 @@ docker run --rm mcr.microsoft.com/dotnet/samples ## Build a .NET image -You can build and run a .NET-based container image using the following instructions: +You can build and run an image using the following instructions (if you've cloned this repo): ```console docker build --pull -t dotnetapp . -docker run --rm dotnetapp Hello .NET from Docker -``` - -You can use the `docker images` command to see a listing of your image, as you can see in the following example. - -```console -% docker images dotnetapp -REPOSITORY TAG IMAGE ID CREATED SIZE -dotnetapp latest baee380605f4 14 seconds ago 189MB -``` - -The logic to build the image is described in the [Dockerfile](Dockerfile), which follows. - -```Dockerfile -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY *.csproj . -RUN dotnet restore - -# copy and publish app and libraries -COPY . . -RUN dotnet publish -c Release -o /app --no-restore - -# final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0 -WORKDIR /app -COPY --from=build /app . -ENTRYPOINT ["dotnet", "dotnetapp.dll"] -``` - -The `sdk:7.0` and `runtime:7.0` tags are both multi-arch tags that will result in an image that is compatible for the given chip and OS. These simple tags (only contain a version number) are great to get started with Docker because they adapt to your environment. We recommend using an OS-specific tag for the runtime for production applications to ensure that you always get the OS you expect. This level of specification isn't needed for the SDK in most cases. - -This Dockerfile copies and restores the project file as the first step so that the results of those commands can be cached for subsequent builds since project file edits are less common than source code edits. Editing a `.cs` file, for example, does not invalidate the layer created by copying and restoring project file, which makes subsequent docker builds much faster. - -Notes: - -- See [Establishing docker environment](../establishing-docker-environment.md) for more information on correctly configuring Dockerfiles and `docker build` commands. -- See [Building for a platform](../build-for-a-platform.md) for instructions on how to target specific platforms. -- See [Enable globalization](../enable-globalization.md) for instructions on how to install system globalization libraries. - -## Build an image for Alpine, Debian or Ubuntu - -.NET multi-platform tags result in Debian-based images, for Linux. For example, you will pull a Debian-based image if you use a simple version-based tag, such as `7.0`, as opposed to a distro-specific tag like `7.0-alpine`. - -This sample includes Dockerfile examples that explicitly target Alpine, Debian and Ubuntu. Docker makes it easy to use alternate Dockerfiles by using the `-f` argument. - -The following example demonstrates targeting distros explicitly and also shows the size differences between the distros. Tags are added to the image name to differentiate the images. - -```console -docker build --pull -t dotnetapp:debian -f Dockerfile.debian-x64 . -docker build --pull -t dotnetapp:ubuntu -f Dockerfile.ubuntu-x64 . -docker build --pull -t dotnetapp:alpine -f Dockerfile.alpine-x64 . -``` - -You can use `docker images` to see the images you've built and to compare file sizes: - -```console -% docker images dotnetapp -REPOSITORY TAG IMAGE ID CREATED SIZE -dotnetapp alpine 8933fb9821e8 8 seconds ago 87MB -dotnetapp ubuntu 373df08a06ec 25 seconds ago 187MB -dotnetapp debian 229dd121a96b 39 seconds ago 190MB -dotnetapp latest 303eabf97376 56 seconds ago 190MB -``` - -You can run any of the images you've just built with the following commands: - -```console docker run --rm dotnetapp -docker run --rm dotnetapp:debian -docker run --rm dotnetapp:ubuntu -docker run --rm dotnetapp:alpine ``` -If you want to double check the distro of an application, you can do that by configuring a different entrypoint when you run the image, as you see in the following example. +You can also pass your own message to the app as an argument. -```console -% docker run --rm --entrypoint cat dotnetapp /etc/os-release -PRETTY_NAME="Debian GNU/Linux 10 (buster)" -NAME="Debian GNU/Linux" -VERSION_ID="10" -VERSION="10 (buster)" -VERSION_CODENAME=buster -ID=debian -HOME_URL="https://www.debian.org/" -SUPPORT_URL="https://www.debian.org/support" -BUG_REPORT_URL="https://bugs.debian.org/" - -% docker run --rm --entrypoint cat dotnetapp:alpine /etc/os-release -NAME="Alpine Linux" -ID=alpine -VERSION_ID=3.10.3 -PRETTY_NAME="Alpine Linux v3.10" -HOME_URL="https://alpinelinux.org/" -BUG_REPORT_URL="https://bugs.alpinelinux.org/" -``` +## Supported Linux distros -## Build an image for Windows Nano Server +The .NET Team publishes images for [multiple distros](../../documentation/supported-platforms.md). -You can target Nano Server directly in the same as you can with Linux. See [Windows container version compatibility](https://docs.microsoft.com/virtualization/windowscontainers/deploy-containers/version-compatibility) to learn about Windows version container requirements. +Samples are provided for: -All supported versions will be demonstrated in the example below. You are encouraged only to use the version that applies to your environment. +- [Alpine](Dockerfile.alpine) +- [Debian](Dockerfile.debian) +- [Ubuntu](Dockerfile.ubuntu) +- [Ubuntu Chiseled](Dockerfile.chiseled) -This example will work on any supported version of Windows (Windows 10 RS2+). +The default [Dockerfile](Dockerfile) uses a major.minor version tag, which references a multi-platform image that provides Debian and Windows Nano Server images (depending on the requesting client). -```console -docker build --pull -t dotnetapp:nanoserver -f Dockerfile.nanoserver-x64 . -docker run --rm dotnetapp:nanoserver Hello .NET from Nano Server -docker images dotnetapp -``` - -The `Dockerfile.nanoserver-x64` Dockerfile targets a version-specific tag, which will result in a Nano Server version that targets a specific Windows version (and will only work on Windows hosts of the same version or higher). You can update the following the tag to a different version, as needed. - -```console -FROM mcr.microsoft.com/dotnet/runtime:7.0-nanoserver-ltsc2022 -``` - -## Build an image optimized for startup performance - -You can improve startup performance by using [Ready to Run (R2R) compilation](https://github.com/dotnet/runtime/blob/master/docs/design/coreclr/botr/readytorun-overview.md) for your application. You can do this by setting the `PublishReadyToRun` property, which will result in your application being compiled to native code when you publish it. This is what the `-slim` samples do (they are explained shortly). - -You can add the `PublishReadyToRun` property in two ways: - -- Set it in your project file, as: `true` -- Set it on the command line, as: `/p:PublishReadyToRun=true` +More extensive samples are provided for Alpine: -The default `Dockerfile` that come with the sample doesn't use R2R compilation because the application is too small to warrant it. The bulk of the IL code that is executed in this sample application is within the .NET libraries, which are already R2R compiled. +- [Alpine with trimming, ready-to-run compilation, and self-contained publishing](Dockerfile.alpine-slim) +- [Alpine with ICU (for globalization)](Dockerfile.alpine-icu) -## Build an image optimized for size +These patterns can be applied to other distros. -You may want to build a .NET image that is optimized for size. You can do this by publishing an application as [self-contained](https://docs.microsoft.com/dotnet/core/deploying/) (includes the .NET runtime) and then trimmed with the assembly-linker. This approach may be prefered if you are running a single .NET app on a machine. Otherwise, building images on the .NET runtime layer is recommended for better overall performance characteristics (due to layer sharing). - -The following instructions are for x64 only, but can be straightforwardly adapted for use with ARM architectures. - -There are a set of `-slim` Dockerfiles included with this sample that are opted into the following .NET SDK publish operations: - -* **Self-contained deployment** -- Publish .NET runtime(s) with the application. -* **Assembly linking** -- Trim assemblies, including in the .NET framework, to make the application smaller. -* **Ready to Run (R2R) compilation** -- Compile assemblies to R2R format to make startup faster. R2R Compiled assemblies are larger. The benefit of R2R compilation for your application may be outweighed by the size increase, so please do test your application with and without R2R. - -You are encouraged to experiment with these options if you want to see which combination of settings works best for you. - -The following instructions demonstrate how to build the `trim` Dockerfiles: - -```console -docker build --pull -t dotnetapp:debian-slim -f Dockerfile.debian-x64-slim . -docker build --pull -t dotnetapp:ubuntu-slim -f Dockerfile.ubuntu-x64-slim . -docker build --pull -t dotnetapp:alpine-slim -f Dockerfile.alpine-x64-slim . -``` +## Supported Windows versions -It is easy to run them all: - -```console -docker run --rm dotnetapp:debian-slim -docker run --rm dotnetapp:ubuntu-slim -docker run --rm dotnetapp:alpine-slim -``` - -You can then compare sizes between using a shared layer and optimizing for size using the `docker images` command again. The command below uses `grep`. `findstr` on Windows works equally well. - -```console -% docker images dotnetapp | grep alpine -dotnetapp alpine-slim 9d23e22d7229 About a minute ago 46.3MB -dotnetapp alpine 8933fb9821e8 About an hour ago 87MB -% docker images dotnetapp | grep ubuntu -dotnetapp ubuntu-slim fe292390c5fb 52 minutes ago 140MB -dotnetapp ubuntu 373df08a06ec 59 minutes ago 187MB -% docker images dotnetapp | grep debian -dotnetapp debian-slim 41e834fe89e2 52 minutes ago 147MB -dotnetapp debian 229dd121a96b 59 minutes ago 190MB -``` - -> Note: These image sizes are all uncompressed, on-disk sizes. When you pull an image from a registry, it is compressed, such that the size will be significantly smaller. See [Retrieving Docker Image Sizes](https://gist.github.com/MichaelSimons/fb588539dcefd9b5fdf45ba04c302db6) for more information. - -You can do the same thing with Windows Nano Server, as follows: - -```console -docker build --pull -t dotnetapp:nanoserver-slim -f Dockerfile.nanoserver-x64-slim . -``` - -You can then use `docker images` command again. - -```console ->docker images dotnetapp -REPOSITORY TAG IMAGE ID CREATED SIZE -dotnetapp nanoserver-slim 7d3666c3b111 4 seconds ago 285MB -dotnetapp nanoserver 7092d2e6b0a4 9 minutes ago 328MB -``` +The .NET Team publishes images for [multiple Windows versions](../../documentation/supported-platforms.md.md). You must have [Windows containers enabled](https://docs.docker.com/docker-for-windows/#switch-between-windows-and-linux-containers) to use these images. -## More Samples +Samples are provided for -* [.NET Docker Samples](../README.md) -* [.NET Framework Docker Samples](https://github.com/microsoft/dotnet-framework-docker/blob/main/samples/README.md) +- [Nano Server](Dockerfile.nanoserver) +- [Nano Server with trimming, ready-to-run compilation, and self-contained publishing](Dockerfile.nanoserver-slim) +- [Windows Server Core](Dockerfile.windowsservercore) diff --git a/samples/globalapp/README.md b/samples/globalapp/README.md index 63a6b180c5..b66061ff02 100644 --- a/samples/globalapp/README.md +++ b/samples/globalapp/README.md @@ -2,6 +2,10 @@ This [app](Program.cs) is intended for testing .NET APIs that use globalization APIs and concepts. The behavior of these APIs varies depending on how a container (or other environment) is configured. The [Dockerfile](Dockerfile) is intended to aid testing and isn't itself an example of a production Dockerfile. +See [.NET Docker Samples](../README.md) for more samples. + +## Configuration + The behavior of these APIs is affected by: - Presence of `icu` and `tzdata` packages. @@ -9,14 +13,22 @@ The behavior of these APIs is affected by: - The value (or absence) of the `TZ` environment variable. - The value (or absence) of `/etc/timezone` -The recommended way to configure tzdata and timezones is to set the container timezone by using the `TZ` environment variables, as is demonstrated below. +The recommended way to configure [tzdata](https://en.wikipedia.org/wiki/Tz_database) and [timezones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) is to set the container timezone by using the `TZ` environment variables, as is demonstrated below. ```bash -$ docker run --rm -it -e TZ="Etc/UTC" app -$ docker run --rm -it -e TZ=$(cat /etc/timezone) app +$ docker run --rm debian date +Wed Feb 22 03:08:10 UTC 2023 +$ docker run --rm -e TZ="Etc/UTC" debian date +Wed Feb 22 03:08:13 UTC 2023 +$ docker run --rm -e TZ=$"America/New_York" debian date +Tue Feb 21 22:08:16 EST 2023 +$ docker run --rm -e TZ=$"America/Los_Angeles" debian date +Tue Feb 21 19:08:39 PST 2023 +$ docker run --rm -e TZ=$(cat /etc/timezone) debian date +Tue Feb 21 19:08:44 PST 2023 ``` -The first approach passes the `Etc/UTC` timezone directly, while the second approach passes the host timezone to the container. +The first approach uses the default timezone, which is [UTC](https://en.wikipedia.org/wiki/Coordinated_Universal_Time). The other examples pass specific timezones, including UTC. The last pattern passes the timezone of the host. A machine configured to UTC will produce the following: @@ -25,6 +37,8 @@ A machine configured to UTC will produce the following: Etc/UTC ``` +## Running the app + The app produces the following output, for the "America/Los_Angeles" timezone: ```bash From 9e4df2e19f567bb2ce129b6ac573a3c4146860f6 Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Sat, 1 Apr 2023 10:26:18 -0700 Subject: [PATCH 04/11] Update READMEs --- README.samples.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.samples.md b/README.samples.md index bf63c097a7..dd21f03fda 100644 --- a/README.samples.md +++ b/README.samples.md @@ -60,19 +60,19 @@ See [Hosting ASP.NET Core Images with Docker over HTTPS](https://github.com/dotn ## Linux amd64 Tags Tags | Dockerfile | OS Version -----------| -------------| ------------- -dotnetapp-alpine-slim-amd64, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-x64-slim) | Alpine +dotnetapp-alpine-slim-amd64, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-slim) | Alpine aspnetapp-alpine-slim-amd64, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-slim) | Alpine ## Linux arm32 Tags Tags | Dockerfile | OS Version -----------| -------------| ------------- -dotnetapp-alpine-slim-arm32v7, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-arm32-slim) | Alpine +dotnetapp-alpine-slim-arm32v7, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-slim) | Alpine aspnetapp-alpine-slim-arm32v7, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-slim) | Alpine ## Linux arm64 Tags Tags | Dockerfile | OS Version -----------| -------------| ------------- -dotnetapp-alpine-slim-arm64v8, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-arm64-slim) | Alpine +dotnetapp-alpine-slim-arm64v8, dotnetapp, latest | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-slim) | Alpine aspnetapp-alpine-slim-arm64v8, aspnetapp | [Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/aspnetapp/Dockerfile.alpine-slim) | Alpine ## Nano Server 2022 amd64 Tags From 3454fea23a104c42935f4f98e382be8efea5b226 Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Sat, 1 Apr 2023 10:59:06 -0700 Subject: [PATCH 05/11] Update complexapp Dockerfile --- samples/complexapp/Dockerfile | 18 +++++++++--------- samples/complexapp/README.md | 8 +++++++- samples/selecting-tags.md | 8 +------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/samples/complexapp/Dockerfile b/samples/complexapp/Dockerfile index b596d4de51..d884b878ad 100644 --- a/samples/complexapp/Dockerfile +++ b/samples/complexapp/Dockerfile @@ -6,30 +6,30 @@ WORKDIR /source COPY complexapp/*.csproj complexapp/ COPY libfoo/*.csproj libfoo/ COPY libbar/*.csproj libbar/ -RUN dotnet restore complexapp/complexapp.csproj --use-current-runtime +RUN dotnet restore complexapp/complexapp.csproj # copy and build app and libraries COPY complexapp/ complexapp/ COPY libfoo/ libfoo/ COPY libbar/ libbar/ -WORKDIR /source/complexapp -RUN dotnet build --use-current-runtime --no-restore # test stage -- exposes optional entrypoint # target entrypoint with: docker build --target test FROM build AS test -WORKDIR /source/tests -COPY tests/*.csproj . -RUN dotnet restore tests.csproj +COPY tests/*.csproj tests/ +WORKDIR /source/tests +RUN dotnet restore COPY tests/ . -RUN dotnet build --use-current-runtime --no-restore +RUN dotnet build --no-restore + +ENTRYPOINT ["dotnet", "test", "--logger:trx", "--no-build"] -ENTRYPOINT ["dotnet", "test", "--logger:trx", "--no-restore", "--no-build"] FROM build AS publish -RUN dotnet publish --use-current-runtime --no-build -o /app +WORKDIR /source/complexapp +RUN dotnet publish --no-restore -o /app # final stage/image FROM mcr.microsoft.com/dotnet/runtime:7.0 diff --git a/samples/complexapp/README.md b/samples/complexapp/README.md index 0e0bdaf070..004621f30c 100644 --- a/samples/complexapp/README.md +++ b/samples/complexapp/README.md @@ -59,9 +59,15 @@ The [Dockerfile](Dockerfile) includes a `test` stage that demonstrates running v # test stage -- exposes optional entrypoint # target entrypoint with: docker build --target test FROM build AS test + +COPY tests/*.csproj tests/ WORKDIR /source/tests +RUN dotnet restore + COPY tests/ . -ENTRYPOINT ["dotnet", "test", "--logger:trx"] +RUN dotnet build --no-restore + +ENTRYPOINT ["dotnet", "test", "--logger:trx", "--no-build"] ``` The presence of the `test` stage costs very little and doesn't significantly change the behavior of the build if you don't specifically target it. By default, the test stage `ENTRYPOINT` will not be used if you build this Dockerfile diff --git a/samples/selecting-tags.md b/samples/selecting-tags.md index 03c96276db..ffc93edb3c 100644 --- a/samples/selecting-tags.md +++ b/samples/selecting-tags.md @@ -78,7 +78,7 @@ docker pull mcr.microsoft.com/dotnet/runtime:6.0-alpine Globalization Support: -By default, the `icu-libs` package is not included and the [globalization invariant mode](https://github.com/dotnet/runtime/blob/main/docs/design/features/globalization-invariant-mode.md) is enabled. You can opt into globalization support by [following the pattern shown in the sample Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-x64#L19). +By default, the `icu-libs` package is not included and the [globalization invariant mode](https://github.com/dotnet/runtime/blob/main/docs/design/features/globalization-invariant-mode.md) is enabled. You can opt into globalization support by [following the pattern shown in the sample Dockerfile](https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-icu). ### Windows @@ -139,9 +139,3 @@ Each container image is generated for a specific processor architecture and oper For multi-stage Dockerfiles, there are typically at least two tags referenced, an SDK and a runtime tag. It is fine to use a multi-platform tag for the SDK. That's the pattern used for .NET samples. You will pull an SDK image that works on your machine. It is important to define a .NET runtime (`runtime-deps`, `runtime`, or `aspnet`) that matches your production environment. Linux containers are flexible. As long as the processor architecture matches, you can run Alpine, Debian and Ubuntu (the distros we produce images for) in any environment that supports Linux containers. [Windows images are more restricted](https://docs.microsoft.com/virtualization/windowscontainers/deploy-containers/version-compatibility). You cannot load containers for newer Windows versions on older hosts. For the best experience, the Windows container version should match the host Windows version. - -There are multiple patterns used in the samples: - -* Multi-platform tags for both SDK and runtime (can be built and run in any single environment) -- see [dotnetapp/Dockerfile](dotnetapp/Dockerfile) and [aspnetapp/Dockerfile](dotnetapp/Dockerfile) -* Multi-platform tag for the SDK and architecture-specific Linux runtime tag (can be built on any environment that supports Linux containers and run in any processor-specific environment that supports Linux containers) -- see [dotnetapp/Dockerfile.alpine-x64](dotnetapp/Dockerfile.alpine-x64) and [aspnetapp/Dockerfile.alpine-arm64](aspnetapp/Dockerfile.alpine-arm64) -* Multi-platform tag for the SDK and a Windows-version-specific runtime tag (can be built on any environment that supports Windows containers and run in any processor-specific environment that supports the specific Windows versions) -- see [dotnetapp/Dockerfile.nanoserver-x64](dotnetapp/Dockerfile.nanoserver-x64) From 6855c2918b17d90fa3aa21d1d84156b62839132e Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Sat, 1 Apr 2023 11:16:10 -0700 Subject: [PATCH 06/11] Update test data --- .../Microsoft.DotNet.Docker.Tests/TestData.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/TestData.cs b/tests/Microsoft.DotNet.Docker.Tests/TestData.cs index fee29e7349..ba2a66a0c1 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/TestData.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/TestData.cs @@ -93,17 +93,17 @@ public static class TestData new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Amd64 }, new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Arm }, new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Arm64 }, - new SampleImageData { OS = OS.Alpine, Arch = Arch.Arm64, DockerfileSuffix = "alpine-arm64" }, - new SampleImageData { OS = OS.Alpine, Arch = Arch.Amd64, DockerfileSuffix = "alpine-x64" }, - new SampleImageData { OS = OS.Alpine, Arch = Arch.Amd64, DockerfileSuffix = "alpine-x64-slim" }, - new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Arm, DockerfileSuffix = "debian-arm32" }, - new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Arm64, DockerfileSuffix = "debian-arm64" }, - new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Amd64, DockerfileSuffix = "debian-x64" }, - new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Amd64, DockerfileSuffix = "debian-x64-slim" }, - new SampleImageData { OS = OS.Jammy, Arch = Arch.Arm, DockerfileSuffix = "ubuntu-arm32" }, - new SampleImageData { OS = OS.Jammy, Arch = Arch.Arm64, DockerfileSuffix = "ubuntu-arm64" }, - new SampleImageData { OS = OS.Jammy, Arch = Arch.Amd64, DockerfileSuffix = "ubuntu-x64" }, - new SampleImageData { OS = OS.Jammy, Arch = Arch.Amd64, DockerfileSuffix = "ubuntu-x64-slim" }, + new SampleImageData { OS = OS.Alpine, Arch = Arch.Arm64, DockerfileSuffix = "alpine" }, + new SampleImageData { OS = OS.Alpine, Arch = Arch.Amd64, DockerfileSuffix = "alpine" }, + new SampleImageData { OS = OS.Alpine, Arch = Arch.Amd64, DockerfileSuffix = "alpine-slim" }, + new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Arm, DockerfileSuffix = "debian" }, + new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Arm64, DockerfileSuffix = "debian" }, + new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Amd64, DockerfileSuffix = "debian" }, + new SampleImageData { OS = OS.BullseyeSlim, Arch = Arch.Amd64, DockerfileSuffix = "debian-slim" }, + new SampleImageData { OS = OS.Jammy, Arch = Arch.Arm, DockerfileSuffix = "ubuntu" }, + new SampleImageData { OS = OS.Jammy, Arch = Arch.Arm64, DockerfileSuffix = "ubuntu" }, + new SampleImageData { OS = OS.Jammy, Arch = Arch.Amd64, DockerfileSuffix = "ubuntu" }, + new SampleImageData { OS = OS.Jammy, Arch = Arch.Amd64, DockerfileSuffix = "ubuntu-slim" }, }; private static readonly SampleImageData[] s_windowsSampleTestData = @@ -111,16 +111,16 @@ public static class TestData new SampleImageData { OS = OS.NanoServer1809, Arch = Arch.Amd64, IsPublished = true }, new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, IsPublished = true }, - new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "nanoserver-x64" }, - new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "nanoserver-x64-slim" }, + new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "nanoserver" }, + new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "nanoserver-slim" }, // Use Nano Server as the OS even though the Dockerfiles are for Windows Server Core. This is because the OS value // needs to match the filter set by the build/test job. We only produce builds jobs based on what's in the manifest // and the manifest only defines Nano Server-based Dockerfiles. So we just need to piggyback on the Nano Server // jobs in order to test the Windows Server Core samples. - new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-x64" }, - new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-iis-x64" }, - new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-x64-slim" }, + new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore" }, + new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-iis" }, + new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-slim" }, }; private static readonly ProductImageData[] s_linuxMonitorTestData = From 1623568d2b89b2ec1d82468a190ad03597f961d6 Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Sat, 1 Apr 2023 11:53:18 -0700 Subject: [PATCH 07/11] Update TestData.cs --- tests/Microsoft.DotNet.Docker.Tests/TestData.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/TestData.cs b/tests/Microsoft.DotNet.Docker.Tests/TestData.cs index ba2a66a0c1..a45a1375c0 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/TestData.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/TestData.cs @@ -120,7 +120,6 @@ public static class TestData // jobs in order to test the Windows Server Core samples. new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore" }, new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-iis" }, - new SampleImageData { OS = OS.NanoServerLtsc2022, Arch = Arch.Amd64, DockerfileSuffix = "windowsservercore-slim" }, }; private static readonly ProductImageData[] s_linuxMonitorTestData = From db54320e51aec076993669b813325b5f1b0ad041 Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Mon, 3 Apr 2023 13:01:58 -0700 Subject: [PATCH 08/11] Update per feedback --- samples/README.md | 4 ++-- tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/samples/README.md b/samples/README.md index 2edc29373b..9d7d456a38 100644 --- a/samples/README.md +++ b/samples/README.md @@ -24,8 +24,8 @@ The following samples and guidance demonstrate how to use .NET and Docker for de ## Hosting guidance * [Host ASP.NET Core Images with container and HTTPS](host-aspnetcore-https.md) -* [Push container Images to Azure Container Registry](push-image-to-acr.md) -* [Push container Images to Docker Hub](push-image-to-dockerhub.md) +* [Push container images to Azure Container Registry](push-image-to-acr.md) +* [Push container images to Docker Hub](push-image-to-dockerhub.md) * [Deploy ASP.NET Core Applications to Azure Container Instances](deploy-container-to-aci.md) ## Other documentation diff --git a/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs index 1d09cdebc7..a7e199b946 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs @@ -36,14 +36,9 @@ public static IEnumerable GetImageData() [DotNetTheory] [MemberData(nameof(GetImageData))] - public async Task VerifyDotnetSample(SampleImageData imageData) + public Task VerifyDotnetSample(SampleImageData imageData) { - if (imageData.DockerfileSuffix == "windowsservercore-iis-x64") - { - return; - } - - await VerifySampleAsync(imageData, SampleImageType.Dotnetapp, (image, containerName) => + return VerifySampleAsync(imageData, SampleImageType.Dotnetapp, (image, containerName) => { string output = DockerHelper.Run(image, containerName); Assert.True(output.Contains("42") || output.StartsWith("Hello")); From aae92154fd339af3f943b1ab31f79ed7fae56653 Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Tue, 4 Apr 2023 08:23:10 -0700 Subject: [PATCH 09/11] Update SampleImageTests.cs --- tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs index a7e199b946..4cb25004a5 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs @@ -36,9 +36,14 @@ public static IEnumerable GetImageData() [DotNetTheory] [MemberData(nameof(GetImageData))] - public Task VerifyDotnetSample(SampleImageData imageData) + public async Task VerifyDotnetSample(SampleImageData imageData) { - return VerifySampleAsync(imageData, SampleImageType.Dotnetapp, (image, containerName) => + if (imageData.DockerfileSuffix == "windowsservercore-iis") + { + return; + } + + async VerifySampleAsync(imageData, SampleImageType.Dotnetapp, (image, containerName) => { string output = DockerHelper.Run(image, containerName); Assert.True(output.Contains("42") || output.StartsWith("Hello")); From 2a3b68dd1f90884f712b2438433d6846be0b8280 Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Tue, 4 Apr 2023 08:23:44 -0700 Subject: [PATCH 10/11] Update SampleImageTests.cs --- tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs index 4cb25004a5..9ac7567407 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs @@ -43,7 +43,7 @@ public async Task VerifyDotnetSample(SampleImageData imageData) return; } - async VerifySampleAsync(imageData, SampleImageType.Dotnetapp, (image, containerName) => + await VerifySampleAsync(imageData, SampleImageType.Dotnetapp, (image, containerName) => { string output = DockerHelper.Run(image, containerName); Assert.True(output.Contains("42") || output.StartsWith("Hello")); From 654dbd52d157901292a22f20bf34006ff0a27bb6 Mon Sep 17 00:00:00 2001 From: Rich Lander Date: Tue, 4 Apr 2023 08:39:31 -0700 Subject: [PATCH 11/11] Update tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs Co-authored-by: Matt Thalman --- tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs index 9ac7567407..180a3f72a4 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs +++ b/tests/Microsoft.DotNet.Docker.Tests/SampleImageTests.cs @@ -36,7 +36,7 @@ public static IEnumerable GetImageData() [DotNetTheory] [MemberData(nameof(GetImageData))] - public async Task VerifyDotnetSample(SampleImageData imageData) + public async Task VerifyDotnetSample(SampleImageData imageData) { if (imageData.DockerfileSuffix == "windowsservercore-iis") {