<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Avinash</title>
    <description>The latest articles on Forem by Avinash (@avinashth).</description>
    <link>https://forem.com/avinashth</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F406505%2F46c77645-7f90-4b18-a2b8-329e73bfa4a0.jpeg</url>
      <title>Forem: Avinash</title>
      <link>https://forem.com/avinashth</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/avinashth"/>
    <language>en</language>
    <item>
      <title>Publish Docker Image In To Docker Hub</title>
      <dc:creator>Avinash</dc:creator>
      <pubDate>Tue, 16 Jun 2020 11:19:26 +0000</pubDate>
      <link>https://forem.com/avinashth/publish-docker-image-in-to-docker-hub-4bc4</link>
      <guid>https://forem.com/avinashth/publish-docker-image-in-to-docker-hub-4bc4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hello Everyone&lt;/strong&gt;, in this article we will&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add Docker support to .net core web API application using visual 
studio. &lt;/li&gt;
&lt;li&gt;How to debug your application, running the image through container.&lt;/li&gt;
&lt;li&gt;Create the latest image of application for release.&lt;/li&gt;
&lt;li&gt;Publish image in to Docker Hub.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Visual studio&lt;/li&gt;
&lt;li&gt;Docker installed&lt;/li&gt;
&lt;li&gt;.net core SDK&lt;/li&gt;
&lt;li&gt;Docker Hub account&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope you guys are ready with prerequisites before starting further steps. Lets get started.&lt;/p&gt;

&lt;p&gt;Create .net core web API project using below command and open in visual studio.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dotnet new webapi -n WhetherForecastAPI&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Verify the web app is created properly by running the application and navigating to the below route.Once done you will be able to see whether report as response.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://localhost:{host number}/weatherforecast&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;OK, now we have our web app ready let us add docker support to our app.&lt;/p&gt;

&lt;p&gt;Right-Click on the project &lt;strong&gt;WhetherForecastAPI&lt;/strong&gt; then click on &lt;strong&gt;add&lt;/strong&gt; select &lt;strong&gt;Docker Support&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--92-UtAlm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8w9xr26mrm6hkdtl86d3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--92-UtAlm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8w9xr26mrm6hkdtl86d3.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As soon as you click on docker support visual studio will ask docker file option select based on your current docker container OS &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nwlENMJz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d4vb16v6w80bff00u9pq.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nwlENMJz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/d4vb16v6w80bff00u9pq.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you add docker support to your project visual studio is going to add two new file in solution i.e &lt;strong&gt;Dockerfile&lt;/strong&gt; and &lt;strong&gt;.dockerignore&lt;/strong&gt;.&lt;br&gt;
Along with the package reference &lt;strong&gt;"Microsoft.VisualStudio.Azure.Containers.Tools.Targets"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that we have added docker support to application.&lt;/p&gt;

&lt;p&gt;Developer will not create image directly in first go and publish it.&lt;br&gt;
They will make changes in their code several times by debugging. Hence in next step we are going to see how we can debug our app.&lt;/p&gt;

&lt;p&gt;It is as simple as we debug our regular application.Select &lt;strong&gt;Solution configuration&lt;/strong&gt; as &lt;strong&gt;debug&lt;/strong&gt; and &lt;strong&gt;Docker&lt;/strong&gt; in place &lt;strong&gt;IIS Express&lt;/strong&gt; as shown in the below image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tnqp972e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b8aweyzt2dz4uh8gj5rl.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tnqp972e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b8aweyzt2dz4uh8gj5rl.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we run, visual studio will create the image of an application and runs that image in a local container.Application will run in your browser just put the break point and debug as normal application.&lt;/p&gt;

&lt;p&gt;As of now our application will be running as image which is tagged ad &lt;br&gt;
dev for example whetherforecastapi: dev&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a_DvTWqa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c6qy5m1q9rtab6t0nqkd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a_DvTWqa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c6qy5m1q9rtab6t0nqkd.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you are done with your changes, next step is to create a latest image of an application for release. In order to that select &lt;strong&gt;Release&lt;/strong&gt; from Solution configuration as shown in below image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MY-8ltmM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y50eemy3ncfyun2liup1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MY-8ltmM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y50eemy3ncfyun2liup1.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As soon as you run the application latest image will be created and which is ready to publish.&lt;/p&gt;

&lt;p&gt;Run below command to see the created image.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker images&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yXZ43Jvx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/843mssbxwrcc3evmea8g.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yXZ43Jvx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/843mssbxwrcc3evmea8g.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As mentioned in prerequisite you should have docker hub account. Login to that account and create repository in &lt;a href="https://hub.docker.com"&gt;Docker Hub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Login in command line to tag that repository to your image and push that image to docker hub.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker login&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;To tag your image to docker hub repository&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker tag whetherforecastapi {repository/name}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Publish your image to docker hub&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker push {repository/name}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: Replace {repository/name} with the newly created repository name.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, We have successfully pushed the image in to docker hub and if we made our repository as public then anybody can access that by pulling that image.&lt;/p&gt;

&lt;p&gt;Hope you guys enjoyed it.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>dotnet</category>
      <category>dockerhub</category>
      <category>debug</category>
    </item>
    <item>
      <title>Containerize a .NET Core Web API Project</title>
      <dc:creator>Avinash</dc:creator>
      <pubDate>Thu, 11 Jun 2020 13:01:45 +0000</pubDate>
      <link>https://forem.com/avinashth/containerize-a-net-core-web-api-project-4p05</link>
      <guid>https://forem.com/avinashth/containerize-a-net-core-web-api-project-4p05</guid>
      <description>&lt;p&gt;Hey, As the world is moving towards lighter things so the software's.&lt;/p&gt;

&lt;p&gt;In this article you are going to learn, how we can create an image of an basic .net core web API application and run that in a container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Docker installed&lt;/li&gt;
&lt;li&gt;.net core SDK &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Verify that environment is ready by executing below commands in cmd.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet --version 
  3.1.101

docker --version
  Docker version 19.03.8, build afacb8b

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Before creating the image of an application. Let us create .net core web API application using below command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dotnet new webapi -n TestWebAPI&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the application is created, navigate to folder under which application is created&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd TestWebAPI&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Before adding the .NET Core app to the Docker image, first it must &lt;br&gt;
   be published.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dotnet publish -c Release&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We are ready with Application which needs to be created as a image.&lt;/p&gt;

&lt;p&gt;Create a file named Dockerfile in directory containing the .csproj &lt;br&gt;
   and open it in a text editor copy below code into that file.&lt;br&gt;
   Dockerfile will be used by docker build command to create image&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1

 COPY bin/Release/netcoreapp3.1/publish/ TestWebAPI/
 WORKDIR /TestWebAPI
 ENTRYPOINT ["dotnet", "TestWebAPI.dll"]

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create image of an application.Below command will use the commands &lt;br&gt;
 in Dockerfile to create image of an application.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker build -t testimage -f Dockerfile .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To get the list of images.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker images&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Container is a instance of an image. Create container to run &lt;br&gt;
   created image in it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker create --name testcontainer testimage&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To get the list of container.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker ps -a&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The status of the container will be &lt;code&gt;created&lt;/code&gt; and not &lt;code&gt;Up&lt;/code&gt; &lt;br&gt;
   until we start the container using below command.&lt;/p&gt;

&lt;p&gt;Start container&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker start testcontainer&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After starting the container we have to run the container in one of the port.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run -p 8080:80 testimage&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open in the browser&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http://localhost:8080/weatherforecast&lt;/code&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>container</category>
      <category>webapi</category>
    </item>
  </channel>
</rss>
