当我创建用于部署的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)
答案 0 :(得分:1)
您要在构建容器映像中安装libgdiplus,但不能在最终容器映像中安装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
[...]
答案 1 :(得分:1)
以下是您如何构建自定义docker映像来处理dotnetcore 2.2中的此问题的方法:
我必须使用此过程将所有必需的库添加到我的容器中,以便它可以与system.drawing一起使用。可能必须为3.1更新。我今天实际上正在为3.1工作,所以我将在找到它们时提供所有更新的说明:
1)docker pull ubuntu
2)docker运行-t ubuntu:latest / bin / bash->打开容器外壳->
3)apt-get更新apt
4)apt-get install wget
5)wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -Opackages-microsoft-prod.deb
6)dpkg -i软件包-microsoft-prod.deb
7)apt-get install apt-transport-https
8)易于获取更新
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 / *