Running a Standard .NET Console Application in Docker Container

Introduction

In this article, we are going to build a docker image of a console application in the .NET Framework.

We have many console apps in the .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 with the best conclusion. Read the article and follow it step by step and your docker solution will be available for you within a few minutes:

Requirements

  1. Docker Desktop (On Windows)
  2. Docker file (Provided in the zip file)

Docker File

Docker File

FROM mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019,

Download the base image from the docker hub to run the application.

WORKDIR /app

Make a working directory for an application called app.

EXPOSE 80

Expose the port if required on the port where your application is listening (Don't require it 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 ."
    Build

After the downloading of the base image, all remaining steps are completed and now the image is available to run.

Base image

Here you can see the image dokcerdemo:latest is available now we can run it and show the output.

Run this command.

docker run dockerdemo:latest

Running Application

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.