我已经按照以下步骤进行:
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
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"]
我尝试添加了以下几行代码:
# 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/*
然而,这没有起任何作用。我该怎么解决这个问题?或者是否有另一种方法可以解决,而不使用System.Drawing.Common。
然而,它并没有起作用。我该如何解决这个问题?
或者,有没有一种避免使用system.drawing的编码方式?
base
中,它应该可以工作。 - Tran Nguyen