Have you read my previous post about .NET 7 and the new feature of dotnet publish? I recommend reading that post because I won't cover some steps.
Preparation
- .NET 8 SDK - When posting this, the version is a preview version.
- Docker
Starter Project
You can try cloning from the net7.0
branch from this repository.
The changes
-
Update
DockerNetExample/DockerNetExample.csproj
. We update the TargetFramework tonet7.0
and addContainerBaseImage
. Normally, we don't addContainerBaseImage
, but because currently still a preview version, I recommend adding it. We also can addContainerImageTags
to distinguish from the previous version.
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <ContainerImageName>docker-net-example</ContainerImageName> <ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:8.0-preview</ContainerBaseImage> <ContainerImageTags>2.0.0;latest</ContainerImageTags> </PropertyGroup> </Project>
Now, let's run the dotnet publish command. Command:
dotnet publish --os linux --arch x64 /t:PublishContainer -c Release
.-
Checking the docker image.
docker image ls
-
I will introduce you to a Docker Compose. If you are using Docker Desktop, you already have Docker Compose bundled. More information about Docker Compose. You can create a file
docker-compose.yml
.
version: "3.9" services: dotnet: image: "docker-net-example:2.0.0" ports: - 8000:80 environment: - ASPNETCORE_URLS=http://+
You can check the detailed PR here.
-
You can test using
curl
or other tools.
Thanks
If you have any feedback, feel free to share it with me in this post or raise an issue in the repository.
Repository
bervProject / docker-net-example
.NET Dockerfile
Docker .NET Example
Blog Post
.NET 6
Please check net6.0 branch.
.NET 7
Please check net7.0 branch.
License
MIT
Top comments (0)