DEV Community

Cover image for .NET 8 + Docker
Bervianto Leo Pratama
Bervianto Leo Pratama

Posted on

6

.NET 8 + Docker

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

  1. .NET 8 SDK - When posting this, the version is a preview version.
  2. Docker

Starter Project

You can try cloning from the net7.0 branch from this repository.

The changes

  1. Update DockerNetExample/DockerNetExample.csproj. We update the TargetFramework to net7.0 and add ContainerBaseImage. Normally, we don't add ContainerBaseImage, but because currently still a preview version, I recommend adding it. We also can add ContainerImageTags 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>
    
  2. Now, let's run the dotnet publish command. Command: dotnet publish --os linux --arch x64 /t:PublishContainer -c Release.

  3. Checking the docker image. docker image ls

    docker image ls

  4. 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://+
    
  5. You can check the detailed PR here.

  6. You can test using curl or other tools.

    test

Thanks

If you have any feedback, feel free to share it with me in this post or raise an issue in the repository.

GIF YES

Repository




Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

Sentry workshop image

Sick of your mobile apps crashing?

Let Simon Grimm show you how to fix them without the guesswork. Join the workshop and get to debugging.

Save your spot →

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay