Building Dotnet core web Api and pushing as a container image to Docker Hub | Creating Docker Hub image from Dotnet Core Api



{tocify} $title={Table of Contents}

Pre-requisite:

  • Dotnet 6
  • Docker Desktop
  • Visual Studio 2022

Creating Dotnet Core Web Api


create new project in Visual Studio


Give a name for the project


Select framework as dotnet 6 and enable Docker 


Solution looks like this


Docker file looks like this



Debugging Api

Click on Run Docker button in Visual studio to debug our Api locally


You will see container window showing something like below image


You can access the swagger page of our Api like this


We can test our Api with Execute option



Publish Our Api to Docker Hub

Right click on project and select Publish


Select Docker Container Registry



Select next and select Docker Hub



Now we have to fill in the username of our Docker Hub account and secret token as password, we will see how to create the secret token for Docker Hub in below section.



Getting Docker Hub credentials


Login to Docker Hub - https://hub.docker.com/

Else create an account in Docker Hub.

Select Account Settings menu on top right corner.


Select Security menu in middle left of the screen.

Click New Access Token option


Provide Description for the Access token - we will give it as 'access-tokenfor-visual studio-publish' for example.


Next to this screen will show you a one-time visible secret token, which you have to copy and save for use in the next section.

Publishing Web Api image to Docker Hub


Go back to Visual studio and fill in the password with the secret token which we got in previous step and click finish.



You are at the end of the publish profile creation and now you will see something like the below screenshot.


Click on Publish on right corner.




You will see the following logs in publish Build log window.




After this you can go to the docker page and find the public image like below screenshot

Link to the Image - Docker Hub








Thanks for reading. ✋😊

Post a Comment

Previous Post Next Post

postad

post ad 2