Thursday, October 1, 2020

Create Docker Image with .Net Core executable

 In the previous post we saw how to create an Executable (.exe file)  for a .Net Core console application. In this post we shall see how to package this .exe into a Docker image and deploy it as a Docker Container. 

First we will have to create a Dockerfile, we will create this file in the publish folder where the publish results (.exe files) are created.    

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1803 AS base
WORKDIR /src
COPY . .
ENTRYPOINT [HelloExe.exe]

Next we will build the Docker image using the following command.

C:\HelloExe\Publish>docker build -t coreexe .
Sending build context to Docker daemon  181.2kB
Step 1/4 : FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1803 AS base
 ---> 62417917ad5b
Step 2/4 : WORKDIR /src
 ---> Running in 1c5df5443d17
Removing intermediate container 1c5df5443d17
 ---> 548168a32dba
Step 3/4 : COPY . .
 ---> 82cb96d10efb
Step 4/4 : CMD ["HelloExe.exe"]
 ---> Running in 91cdd7672f6d
Removing intermediate container 91cdd7672f6d
 ---> 4bc6c0276e56
Successfully built 4bc6c0276e56
Successfully tagged coreexe:latest          

C:\HelloExe\Publish>docker image ls

REPOSITORY                     TAG                   IMAGE ID                CREATED               SIZE
coreexe                                 latest                401fb50e5288        6 seconds ago       509MB


Search Flipkart Products:
Flipkart.com

No comments: