无法加载共享库"libgdiplus" - Docker [.NET应用程序与Aspose API]

31

创建 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 - Lex Li
@LexLi 在删除了这行代码之后,我仍然遇到了同样的问题。实际上,我想要加载这个库 RUN apt-get install -y libgdiplus。它已经被加载了,但错误仍然存在。 - RED.Skull
1
那行代码只是问题的一部分。你还漏掉了一些东西,https://docs.aspose.com/display/pdfnet/Installation#Installation-Workingwith.NETCoreDLLsinNon-WindowsEnvironment 无论如何,你需要从供应商那里获取确切的设置先决条件支持。 - Lex Li
@LexLi 这对 .NET 3.0 同样适用吗? - RED.Skull
@LexLi 感谢分享链接。现在我已将字体复制到应用程序文件夹中。 Aspose.Pdf.Text.FontRepository.Sources.Add(new Aspose.Pdf.Text.FolderFontSource(Path.GetFullPath(Directory.GetCurrentDirectory() + "//fonts//"))); 但它仍在搜索 '/usr/share/fonts/truetype/msttcorefonts'。 - RED.Skull
显示剩余2条评论
3个回答

85

您正在安装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的等效库的方式是否相同? - Parthi

5

6
对我没有用,仍然看到同样的异常。 - Anthony Liriano

3
以下是关于如何构建一个自定义的docker镜像来解决dotnetcore 2.2中的问题的步骤:

1) docker pull ubuntu

2) 运行命令docker run -t ubuntu:latest /bin/bash,打开容器shell

3) 执行apt-get update apt

4) 执行apt-get install 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 update

9) 执行apt-get install dotnet-sdk-2.2 <----这个需要修改

10) 执行apt-get install 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/*

我使用了这个过程来向容器中添加所有必要的库文件,以便它能够与system.drawing一起工作。这可能需要针对3.1进行更新。我今天正在为3.1工作,如果我发现任何更新的说明,我会提供它们。请注意,保留了html标签。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接