Running a Standard .NET Console Application in Docker Container


In this article, we are going to build a docker image of a console application in .NET Framework.
We have many console apps in .NET framework in the industry and try to make it docker compatible, but a proper article for the Dotnet console application is not easily available. Therefore, I am providing the details solution of a .NET framework console application with docker.
After spending a lot of hours on this topic we are providing you the best conclusion. Read the article and follow it step by step and your docker solution is available for you within a few minutes:
  1. Docker Desktop (On Windows)
  2. Docker file (Provided in the zip file)
Docker File
Running A Standard .NET Console Application In Docker Container
Download the base image from the docker hub to run the application.
Make a working directory for an application called app. 
Expose the port if required on the port where your application is listening (Don't required in this application just for information).
COPY /bin/Debug . 
Copy all the Debug folder content to the app folder.
Inside the app folder, the application will be running. 
ENTRYPOINT ["FrameworkConsoleApp.exe"] 
Create an entry point form here. The Application will start if there is no error found.
Now we are going to create the image of the source code for convenience. I am providing the basic console application source code in the zip file format. Download and run it in your local machine. 
Basic steps to create an image on docker:
  1. Open the folder "FrameworkConsoleApp" just you downloaded.
  2. Open CMD and provide the path of the folder.
  3. Run command "docker build -t dockerdemo ." 
Running A Standard .NET Console Application In Docker Container
After that downloading of the base image, all remaining steps are completed and now the image is available to run:
Running A Standard .NET Console Application In Docker Container
Here you can see image dokcerdemo:latest is available now we can run it and show the output.
Run this command:
docker run dockerdemo: latest
Running A Standard .NET Console Application In Docker Container
I am simply writing a line for the console application to test it. You can see this output if no error is available in the source code or in the docker image. You can modify the source code according to your requirements. In the next article, I will show you how to deploy it on Kubernetes.