【问题标题】:Unable to load shared library "libgdiplus" - Docker [ .NET application with Aspose API]无法加载共享库“libgdiplus” - Docker [带有 Aspose API 的 .NET 应用程序]
【发布时间】:2020-03-23 14:34:56
【问题描述】:

当我创建一个用于部署的 docker 文件时,该应用程序通常在开发环境中工作,它因 libgdiplus 问题而失败。

DockerFile

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build


RUN apt-get update && apt-get install -y apt-utils
RUN apt-get install -y libfontconfig1
RUN apt-get install -y libgdiplus
RUN apt-get install -y libc6-dev 
RUN ln -s /usr/lib/libgdiplus.so/usr/lib/gdiplus.dll

# copy csproj and restore as distinct layers
WORKDIR /src
COPY HelloWorld/HelloWorld.csproj HelloWorld/
RUN dotnet restore HelloWorld/HelloWorld.csproj
COPY . .


WORKDIR /src/HelloWorld
RUN dotnet build HelloWorld.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish HelloWorld.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "HelloWorld.dll"]

即使我尝试了以下脚本来加载库,但仍然失败

RUN apt-get update \ 
    && apt-get install -y --allow-unauthenticated \
     libc6-dev \ 
    libgdiplus \ 
    libx11-dev \ 
    && rm -rf /var/lib/apt/lists/*

错误

 Connection id "0HLRJJEGNBH3R", Request id "0HLRJJEGNBH3R:00000001": An unhandled exception was thrown by the application.
Aspose.Slides.PptxReadException: The type initializer for 'Gdip' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibgdiplus: cannot open shared object file: No such file or directory
   at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)

【问题讨论】:

  • RUN ln -s /usr/lib/libgdiplus.so/usr/lib/gdiplus.dll,真的是你用的吗?
  • @LexLi 删除此行后,我仍然遇到同样的问题。实际上我想加载这个库 RUN apt-get install -y libgdiplus。它已加载但错误仍然相同
  • 该行只是问题的一部分。您仍然错过了一些东西,docs.aspose.com/display/pdfnet/… 无论如何,您需要供应商的支持才能获得确切的设置先决条件。
  • @LexLi 是否同样适用于 .NET 3.0?
  • @LexLi 感谢分享链接。现在我将字体复制到应用程序文件夹。 Aspose.Pdf.Text.FontRepository.Sources.Add(new Aspose.Pdf.Text.FolderFontSource(Path.GetFullPath(Directory.GetCurrentDirectory() + "//fonts//")));但它仍在搜索'/usr/share/fonts/truetype/msttcorefonts'

标签: asp.net docker dockerfile aspose


【解决方案1】:

您正在构建容器映像中安装 libgdiplus,但不是在最终容器映像中。您需要确保 libgdiplus 已安装在您的最终容器映像中。

您可以考虑像这样修改您的 Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base
RUN apt-get update && apt-get install -y libgdiplus

WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
[...]

【讨论】:

  • 在docker文件中安装kernel32.dll等价库的方法是一样的吗?
【解决方案2】:

以下是在 dotnetcore 2.2 中构建自定义 docker 映像来处理此问题的方法:

我必须使用此过程将所有必要的库添加到我的容器中,以便它可以与 system.drawing 一起使用。这可能需要为 3.1 更新。我今天实际上正在为 3.1 做这个,所以我会在找到它们时提供任何更新的说明:

1) docker pull ubuntu

2) docker run -t ubuntu:latest /bin/bash -> 打开容器外壳 ->

3) apt-get 更新 apt

4) apt-get 安装 wget

5) wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

6) dpkg -i packages-microsoft-prod.deb

7) apt-get install apt-transport-https

8) apt-get 更新

9) apt-get install dotnet-sdk-2.2

10) apt-get 安装 libgdiplus

11) cd /usr/lib

12) ln -s libgdiplus.so gdiplus.dll

13) apt-get install libc6-dev libx11-dev

14) rm -rf /var/lib/apt/lists/*

【讨论】:

    【解决方案3】:

    .NET6+ 下,您还需要在 runtimeconfig.json 中明确启用对 Windows 以外操作系统下 GDI+ 的 Mono 实现的支持。

    只需在项目同目录下添加一个runtimeconfig.template.json文件即可:

    {
      "configProperties": {
        "System.Drawing.EnableUnixSupport": true
      }
    }
    

    更多信息: https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only

    【讨论】:

      猜你喜欢
      • 2020-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2014-10-26
      • 2014-11-06
      • 2021-11-04
      • 2021-10-12
      相关资源
      最近更新 更多