-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Update .NET guide to .NET 10 #23729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update .NET guide to .NET 10 #23729
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,12 +39,71 @@ | |
|
|
||
| ## Initialize Docker assets | ||
|
|
||
| Now that you have an application, you can use `docker init` to create the | ||
| necessary Docker assets to containerize your application. Inside the | ||
| `docker-dotnet-sample` directory, run the `docker init` command in a terminal. | ||
| `docker init` provides some default configuration, but you'll need to answer a | ||
| few questions about your application. Refer to the following example to answer | ||
| the prompts from `docker init` and use the same answers for your prompts. | ||
| Now that you have an application, you can create the necessary Docker assets to containerize it. You can choose between using the official .NET images or Docker Hardened Images (DHI). | ||
|
|
||
| > [Docker Hardened Images (DHIs)](https://docs.docker.com/dhi/) are minimal, secure, and production-ready container base and application images maintained by Docker. DHI images are recommended for better security—they are designed to reduce vulnerabilities and simplify compliance. | ||
| > **Note**: DHI for .NET 10 is not yet available. The following DHI example uses .NET 9. Check the [DHI catalog](https://hub.docker.com/hardened-images/catalog) for .NET 10 availability, or use the official image tab below for .NET 10. | ||
|
Check warning on line 46 in content/guides/dotnet/containerize.md
|
||
| {{< tabs >}} | ||
| {{< tab name="Using Docker Hardened Images (.NET 9)" >}} | ||
|
|
||
| Docker Hardened Images (DHIs) for .NET are available on [Docker Hub](https://hub.docker.com/hardened-images/catalog/dhi/aspnetcore). Unlike using the Docker Official Image, you must first mirror the image into your organization. Follow the instructions in the [DHI quickstart](/dhi/get-started/) to create a mirrored repository. | ||
|
|
||
| Mirrored repositories must start with `dhi-`, for example: `FROM <your-namespace>/dhi-aspnetcore:<tag>`. | ||
|
|
||
| You can use `docker init` to generate Docker assets, then modify the Dockerfile to use DHI images: | ||
|
|
||
| ```console | ||
| $ docker init | ||
| Welcome to the Docker Init CLI! | ||
|
|
||
| This utility will walk you through creating the following files with sensible defaults for your project: | ||
| - .dockerignore | ||
| - Dockerfile | ||
| - compose.yaml | ||
| - README.Docker.md | ||
|
|
||
| Let's get started! | ||
|
|
||
| ? What application platform does your project use? ASP.NET Core | ||
| ? What's the name of your solution's main project? myWebApp | ||
| ? What version of .NET do you want to use? 9.0 | ||
| ? What local port do you want to use to access your server? 8080 | ||
| ``` | ||
|
|
||
| Then update your Dockerfile to use DHI images: | ||
|
|
||
| ```dockerfile {title=Dockerfile} | ||
| # syntax=docker/dockerfile:1 | ||
|
|
||
| FROM --platform=$BUILDPLATFORM <your-namespace>/dhi-dotnet:9.0-alpine AS build | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got an error from this image. Tag does not exist and I think the sdk variant is required to build. |
||
| ARG TARGETARCH | ||
| COPY . /source | ||
| WORKDIR /source/src | ||
| RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \ | ||
| dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app | ||
|
|
||
| FROM <your-namespace>/dhi-aspnetcore:9.0-alpine AS final | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get an error from this image. Tag does not exist. Updating the tag to |
||
| WORKDIR /app | ||
| COPY --from=build /app . | ||
| ARG UID=10001 | ||
| RUN adduser \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get an error from adduser. I don't think it's included in the image. |
||
| --disabled-password \ | ||
| --gecos "" \ | ||
| --home "/nonexistent" \ | ||
| --shell "/sbin/nologin" \ | ||
| --no-create-home \ | ||
| --uid "${UID}" \ | ||
| appuser | ||
| USER appuser | ||
| ENTRYPOINT ["dotnet", "myWebApp.dll"] | ||
| ``` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even after the above changes, the app still fails to run because it appears to be not compatible with either the original v8 app, or the changes to update the app to v10. |
||
|
|
||
| {{< /tab >}} | ||
| {{< tab name="Using the official .NET 10 image" >}} | ||
|
|
||
| You can use `docker init` to create the necessary Docker assets. Inside the `docker-dotnet-sample` directory, run the `docker init` command in a terminal. `docker init` provides some default configuration, but you'll need to answer a few questions about your application. Refer to the following example to answer the prompts from `docker init` and use the same answers for your prompts. | ||
|
|
||
| ```console | ||
| $ docker init | ||
|
|
@@ -60,10 +119,41 @@ | |
|
|
||
| ? What application platform does your project use? ASP.NET Core | ||
| ? What's the name of your solution's main project? myWebApp | ||
| ? What version of .NET do you want to use? 8.0 | ||
| ? What version of .NET do you want to use? 10.0 | ||
| ? What local port do you want to use to access your server? 8080 | ||
| ``` | ||
|
|
||
| This generates a Dockerfile using the official .NET 10 images from Microsoft Container Registry: | ||
|
|
||
| ```dockerfile {title=Dockerfile} | ||
| # syntax=docker/dockerfile:1 | ||
|
|
||
| FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS build | ||
| ARG TARGETARCH | ||
| COPY . /source | ||
| WORKDIR /source/src | ||
| RUN --mount=type=cache,id=nuget,target=/root/.nuget/packages \ | ||
| dotnet publish -a ${TARGETARCH/amd64/x64} --use-current-runtime --self-contained false -o /app | ||
|
|
||
| FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS final | ||
| WORKDIR /app | ||
| COPY --from=build /app . | ||
| ARG UID=10001 | ||
| RUN adduser \ | ||
| --disabled-password \ | ||
| --gecos "" \ | ||
| --home "/nonexistent" \ | ||
| --shell "/sbin/nologin" \ | ||
| --no-create-home \ | ||
| --uid "${UID}" \ | ||
| appuser | ||
| USER appuser | ||
| ENTRYPOINT ["dotnet", "myWebApp.dll"] | ||
| ``` | ||
|
|
||
| {{< /tab >}} | ||
| {{< /tabs >}} | ||
|
|
||
| You should now have the following contents in your `docker-dotnet-sample` | ||
| directory. | ||
|
|
||
|
|
@@ -78,7 +168,7 @@ | |
| │ └── README.md | ||
| ``` | ||
|
|
||
| To learn more about the files that `docker init` added, see the following: | ||
| To learn more about the files, see the following: | ||
| - [Dockerfile](/reference/dockerfile.md) | ||
| - [.dockerignore](/reference/dockerfile.md#dockerignore-file) | ||
| - [compose.yaml](/reference/compose-file/_index.md) | ||
|
|
@@ -126,6 +216,7 @@ | |
| - [Dockerfile reference](/reference/dockerfile.md) | ||
| - [.dockerignore file reference](/reference/dockerfile.md#dockerignore-file) | ||
| - [Docker Compose overview](/manuals/compose/_index.md) | ||
| - [Docker Hardened Images](/dhi/) | ||
|
|
||
| ## Next steps | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like 10 was just added after you drafted this.