I have followed these steps:
Create a new ASP.NET Core MVC web application without Docker support
Installed the
System.Drawing.Common
Nuget packagesAdd a file called
TestImage.png
Access the file successfully using the following code:
byte[] imageLoaded = System.IO.File.ReadAllBytes("TestImage.png"); Image image; using (MemoryStream mStream = new MemoryStream(imageLoaded)) { image = Image.FromStream(mStream); } var image2 = new Bitmap(image); image2.Save("TestImage1.png", ImageFormat.Png);
Expected behaviour up to now; here is the problematic bit:
Right click on the solution and select: Add Container Orchestration Support/Docker Compose/Linux (target OS)
Run the project (docker-compose is the startup project). I get an error:
DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory
I have done a lot of Googling and found this: Unable to load DLL 'libdl' when using System.Drawing.Common NuGet package on AWS Lambda
Here is my Dockerfile:
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY WebApplication1/WebApplication1.csproj WebApplication1/
RUN dotnet restore WebApplication1/WebApplication1.csproj
COPY . .
WORKDIR /src/WebApplication1
RUN dotnet build WebApplication1.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish WebApplication1.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
I have tried adding the following lines:
# install System.Drawing native dependencies
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
However, it has made no difference. How can I fix this? or Is there another way I can approach this without using System.Drawing.Common.
However, it has not worked. How can I fix this?
Alternatively, is there a way to code this avoiding system.drawing?