【.NET Core】在Docker中找不到gdiplus.dll

原文鏈接:https://en.code-bude.net/2017/05/08/net-core-gdiplus-dll-not-found-in-linux/

你在windows上使用圖像組件沒有任務問題,但部署到linux之後,將注意以下幾點:

  1. 安裝nuget包ZKWeb.System.Drawing
  2. 項目裏還是引用System.DrawingCore,這點不用改
  3. 安裝gdiplus插件,這個需要根據linux類型不同,有不同的方法,大叔做了一下總結

安裝gdiplugs的方法

大叔總結的方法
ubuntu && debian

sudo apt-get install libgdiplus
cd /usr/lib
sudo ln -s libgdiplus.so gdiplus.dll

centos

yum whatprovides libgdiplus && yum install -y epel-release && yum install -y libgdiplus-2.10-9.el7.x86_64 && yum install -y libgdiplus-devel

官方提供的方法:

Ubuntu 16.04:

apt-get install libgdiplus
cd /usr/lib
ln -s libgdiplus.so gdiplus.dll

Fedora 23:

dnf install libgdiplus
cd /usr/lib64/
ln -s libgdiplus.so.0 gdiplus.dll

CentOS 7:

yum install autoconf automake libtool
yum install freetype-devel fontconfig libXft-devel
yum install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-devel
yum install glib2-devel cairo-devel
yum install git
git clone https://github.com/mono/libgdiplus
cd libgdiplus
yum -y install ftp
./autogen.sh
yum -y install gcc automake autoconf libtool make
yum -y install gcc gcc-c++
make
make install
cd /usr/lib64/
ln -s /usr/local/lib/libgdiplus.so gdiplus.dll

Docker:

RUN apt-get update
RUN apt-get install -y libgdiplus
RUN cd /usr/lib
RUN sudo ln -s libgdiplus.so gdiplus.dll

例子:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build

RUN apt-get update
RUN apt-get install -y libgdiplus
RUN cd /usr/lib
RUN sudo ln -s libgdiplus.so gdiplus.dll

WORKDIR /src
COPY ["DC_MMS_API/DC_MMS_API.csproj", "DC_MMS_API/"]
COPY ["Core/Core.csproj", "Core/"]
COPY ["Infrastructure/Infrastructure.csproj", "Infrastructure/"]
RUN dotnet restore "DC_MMS_API/DC_MMS_API.csproj"
COPY . .
WORKDIR "/src/DC_MMS_API"
RUN dotnet build "DC_MMS_API.csproj" -c Release -o /app

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

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章