asp.net - 无法加载共享库 "libgdiplus"- Docker [带有 Aspose API 的 .NET 应用程序]

标签 asp.net docker dockerfile aspose

当我创建一个用于部署的 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)

最佳答案

您正在构建容器镜像中安装 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
[...]

关于asp.net - 无法加载共享库 "libgdiplus"- Docker [带有 Aspose API 的 .NET 应用程序],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59080331/

相关文章:

Dockerfile 缓存不一致

docker - 在dockerfile中升级gcc

c# - 标签助手未在 ASP.NET Core 2 中处理

docker - Kubernetes 使用基础镜像填充

docker - 有没有办法在 kubernetes 中配置 docker hub pro 用户?

docker - 在销毁Docker容器之前如何运行脚本?

docker - Docker-使用标签影响启动顺序

c# - 我应该动态重新创建 PDF,而不是将其存储在数据库或文件系统中吗?

c# - 业务对象数据访问层的最佳 "pattern"

asp.net - 使用选择下拉列表搜索 sql 数据库?