How to create docker image for dotnet app?

706 Views Asked by At

I have a dotnet project that work when i do dotnet run, i am trying to containerize that dotnet project. For that i have create the Dockerfile as below:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1

COPY bin/Release/netcoreapp3.1/publish/ App/
WORKDIR /App

EXPOSE 5000

CMD ["dotnet", "MediatorAgent.dll"]

Before creating the docker image i did run dotnet publish -c Release. Now when i try to run this docker image, i am getting the below error

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'indy' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libindy: cannot open shared object file: No such file or directory

I am following the instruction for Containerize a .NET Core app for creating docker image.

2

There are 2 best solutions below

2
On

How to create docker image for dotnet app?

Well, you did it.

What is likely to have gone wrong is that the DLL refered to as indy is not copied to the App folder.

Since you are copying the data, please verify it's included in the original build at bin/Release/netcoreapp3.1/publish

0
On

make sure bin/Release/ directory available in the same directory where your Dockerfile exist.

You can specify the project .csproj or .sln to build.

You can have a look on below dockerfile, hope that will help you.

FROM microsoft/aspnetcore-build AS builder
WORKDIR /source

COPY projectname.csproj .
RUN dotnet restore
RUN dotnet build projectname.csproj -c Release -o /app/build

COPY . .
RUN dotnet publish -c Release -o /app/publish

FROM microsoft/aspnetcore
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "projectname.dll"]