在Docker内部使用System.Drawing [英] Using System.Drawing inside Docker

查看:138
本文介绍了在Docker内部使用System.Drawing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照以下步骤操作:

I have followed these steps:


  1. 创建一个没有Docker支持的新ASP.NET Core MVC Web应用程序

  1. Create a new ASP.NET Core MVC web application without Docker support

安装了 System.Drawing.Common Nuget软件包

Installed the System.Drawing.Common Nuget packages

添加一个名为 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:

右键单击解决方案,然后选择:添加容器编排支持/ Docker Compose / Linux(目标操作系统)

Right click on the solution and select: Add Container Orchestration Support/Docker Compose/Linux (target OS)

运行项目(docker-compose是启动项目)。我收到一个错误:

Run the project (docker-compose is the startup project). I get an error:


DllNotFoundException:无法加载共享库'libdl'或其依赖项之一。为了帮助诊断加载问题,请考虑设置LD_DEBUG环境变量:liblibdl:无法打开共享对象文件:没有这样的文件或目录

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


我做了很多Google搜索,发现了以下内容:在AWS Lambda上使用System.Drawing.Common NuGet软件包时无法加载DLL'libdl'

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

这是我的Dockerfile:

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"]

我尝试添加以下行:

# 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即可解决此问题的方法。

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?

或者,有一种方法可以编码该代码以避免system.drawing?

Alternatively, is there a way to code this avoiding system.drawing?

推荐答案

我设法使它起作用。
这是我的dockerfile的样子:

I have managed to make this to work. This is how my dockerfile looks like:

(我使用的是.net core 3.0,但在2.x版本中应该可以正常工作)

(I'm using .net core 3.0 but it should work perfectly fine with 2.x versions)

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
RUN apt-get update \ 
    && apt-get install -y --no-install-recommends libgdiplus libc6-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
RUN cd /usr/lib && ln -s libgdiplus.so gdiplus.dll
WORKDIR /app

... the rest of your dockerfile ...

我希望这会有所帮助。

这篇关于在Docker内部使用System.Drawing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆