Skip to main content

Run Your First .Net Core 2.0 Console Application in Windows10 Docker

Problem

How to run my first .net core 2.0 console application in windows10 docker?

Background   

This exercise is for beginners who want to understand Docker fundamental tenets and run their first .net core 2.0 application in windows10 docker.

Solution

Prerequisites 

Use the below link to setup docker on your Windows10 laptop/desktop.


Steps

1. Create new "Console App (.Net Core)" project using "File >> New >> Project" menu.


2. It creates a new project (CoreHelloWorld) with "Program.cs" class with the following lines of code. Execute the project and make sure it works.  😀


3. Make sure docker is running in "Windows Container" mode on your machine. If not, then switch to "Windows Container"

4. Now your application must be packed with its dependencies into a folder for deployment. You may do this with two options.

       a. Run "dotnet publish" command from project root directory
        

        b. Select (CoreHelloWorld) your project, from the context menu, click "Publish". This will open a popup window, from the popup window select "Publish Target" type "Folder" and specify folder name.

        Now files are published into specified folder 

 

5. Add a new file (text ) to your project, then name the file as "Dockerfile"

      

          To know more about "Dockerfile" and image refer the following link



6. You may copy the following contents into "Dockerfile" and do the necessary modification.


FROM microsoft/dotnet

WORKDIR /netcoreapp2.0

COPY /bin/Debug/netcoreapp2.0/publish/ .

ENTRYPOINT ["dotnet", "CoreHelloWorld.dll"]


7. Now the "Dockerfile" is ready, Now run the build command. This creates a Docker image. "-t" you may provide a friendly name (lower case) to Docker image.

 docker build -t corehw . 

"build" command expects the path of the image file. If you are referring the local Dockerfile then don't forget to add "." at the end.


8. Using the following command, make sure the newly created image is available. 

 docker image ls


9. Using the following command, you can run the Docker image.

 docker run --name corehwcontainer corehw


You may also run the Docker image without specifying the "--name" parameter. In that case, daemon generates a random string name for the container. It's always good practice to run with the name.

Using the following command you can list all processes.

 docker ps -a 


10. Both image and container can be deleted using the following commands

  docker rm corehwcontainer 

  docker rmi corehw

Comments

Post a Comment

Popular posts from this blog

How to disable Swagger documentation?

Background   When I was developing foundational RESTful APIs (Web API) for one of our clients, swagger was our choice for documentation. Swagger provides interactive documentation feature with nice UI. Since we were developing only RESTful APIs, QA team members were using Swagger UI to test APIs. Suddenly there was a request from customer to disable swagger in production environment. Solution How to enable swagger? Install "Swashbuckle" nuget package into your WebAPI project.  This installation will add the following entries in "packages.config"   <package id=" Swashbuckle " version="5.5.3" targetFramework="net45" />   <package id=" Swashbuckle.Core " version="5.5.3" targetFramework="net45" /> " SwaggerConfig.cs " file will be added in " App_Start " folder Execute the project code. When the new browser window pops out, add " swagger/ui/...

Unable to get authorization code from PingFederate

Problem I am using PingFederate as key manager for my API Manager. While requesting authorization code for an existing client and resource owner, it was showing the following error message "Server.log" shows the following message 2016-12-13 11:34:03,363 tid:AOf2aORr5j9_X_PHbCTZu-toxwA DEBUG [org.sourceid.websso.servlet.IntegrationControllerServlet] POST: https: <IP> /as/yVKcc/resume/as/authorization.ping 2016-12-13 11:34:03,363 tid:AOf2aORr5j9_X_PHbCTZu-toxwA INFO  [org.sourceid.websso.servlet.IntegrationControllerServlet] org.sourceid.websso.servlet.RenderPageException: Unable to resume processing because saved state was not found for key: BR6msnwXdx33oQX3imDRni_yVKcc - rendering state.not.found.error.page.template.html Background  1. I have following two OAuth clients configured in PingFederate  2. OAuth client "2" was created with the following configuration 3. Using the following url, authorization code was requested  ...

How to configure custom password validator in PingFederate?

Requirement  Use an existing oracle table (password is plain text) in PingFederate to validate user credential for authorization code flow. Analysis By default PingFederate supports the following password validators LDAP Username Password Credentials Validator PingOne Directory Password Credential Validaot RADIUS Username Password Credential Validator Simple Username Password Credential Validator   SQL password validator is not in the list. So how to use an existing oracle table to validate the user credentials. Solution Need to create SQL custom password validator (jar). You may also contact PingFederate support team for this.   Download   How to Configure Custom Password Validator? Stop PingFederate instance Copy the jar file (pf.plugins.password-credential-validator-sql-v2.jar) to the following folder on PingFederate server                  <PingFederateInstall>/pingfederat...