In my previous blog posts, I wrote about the built-in container support in the .NET 7 SDK that allows you to create and publish Docker images for your .NET applications without writing any Dockerfile. I also showed how to use the Chiseled Ubuntu base images optimized for .NET and containers.

For this blog post, I will explain how to publish your Docker images using the .NET SDK to GitHub Packages / Container Registry. It is possible to publish to different container registries, such as Docker Hub, GitHub, Azure Container Registry, or your own private registry. I will show you how to publish to GitHub Packages / Container Registry, but the process is similar for other registries.

This blog post will help you learn how to leverage the .NET SDK’s built-in container support to effortlessly distribute and run your .NET applications in the cloud using Docker. Stay tuned!


To follow along with this blog post, you will need the following

If you target a remote container registry, only the .NET SDK is required.

To publish your Docker images to a local container registry, you will also need

Publish profiles

Like my previous blog post, I will use the publishing profiles to define the Docker image name and tag. I will also use publishing profiles to set the base image and the registry name for the Docker image.

In this blog post, we are focusing on ContainerRegistry and ContainerImageName properties.

GitHub Packages / Container Registry publish profile

Where the new image goes after being created depends on the container registry property, ContainerRegistry, which specifies the target registry. In the case of GitHub Container Registry you need to set ContainerRegistry to

The ContainerImageName needs to be set as a path using your GitHub username, laurentkempe, then / and the name of the image, containerplayground. ContainerImageTag specifies the tag of the image, e.g. 1.0.0. To automate the versioning of your Docker image, you can glance my previous blog in the section “Tagging your image“.

<ContainerPort Include="80" Type="tcp" />

To be able to publish, it is extremely simple with the command specifying the GitHub publish profile.

dotnet publish --os linux --arch x64 -p:PublishProfile=github -c Release

This publishing profile will create a Docker image named

You will then be able to pull it using the following command:

docker pull

or run it

docker run -it --rm -p 8080:80

Finally, browse to http://localhost:8080/ to see the “Hello World!” message.


To publish to a remote container registry, you need to authenticate. The authentication method depends on the registry you are targeting.

Publishing to GitHub Container Registry uses a Personal Access Token (classic) (PAT) with the read:packages and write:packages scopes. You can then use this PAT as your password when authenticating to GitHub Container Registry.

To authenticate to GitHub Container Registry, you can use the docker login command:

docker login -u <username> -p <token>

It is a way of interacting with a Docker config file containing rules for authenticating with specific registries.

You can read more about authenticating to container registries for the .NET SDK here. Or, in our case, about the authentication methods for GitHub Container Registry here.

Supported registries

The .NET SDK supports publishing to any registry that supports the Docker Registry HTTP API V2.

Here is a list of supported registries:


In this blog post, I showed you how to use the .NET SDK’s built-in container support to publish your .NET applications to Docker image. I also demonstrated how to use variables in your project file to customize base image, image tag, and registry name for your Docker images. Finally, I showed you how to publish your Docker images to different container registries, such as GitHub, Azure Container Registry or Docker Hub.