centos下.Netcore的docker容器部署出现“The type initializer for 'Gdip' threw an exception.”
2021/4/20 7:29:41
本文主要是介绍centos下.Netcore的docker容器部署出现“The type initializer for 'Gdip' threw an exception.”,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
今天在.Netcore项目里增加了图片验证码功能,在windows部署下未发现问题,但是在Linux(Centos)下部署却出现了如下问题
查了下是因为用了System.Drawing.Common类库需要在linux下安装一下libgdiplus来支持图像处理,图片处理,因为我的环境是在Docker环境下,所以去要在容器中增加一下
我们在构建的Dockerfile里面增加阿里源以及增加libgdiplus,具体如下
FROM mcr.microsoft.com/dotnet/sdk:5.0 RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so RUN echo "deb http://mirrors.aliyun.com/debian wheezy main contrib non-free \ deb-src http://mirrors.aliyun.com/debian wheezy main contrib non-free \ deb http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free \ deb-src http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free \ deb http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free \ deb-src http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free" > /etc/apt/sources.list RUN apt-get update RUN apt-get install libgdiplus -y && ln -s libgdiplus.so gdiplus.dll COPY . /publish WORKDIR /publish EXPOSE 8801 CMD ["dotnet", "Test.dll", "--urls", "http://*:8801"]
然后我们执行一下,出现了以下问题
Step 4/9 : RUN apt-get update ---> Running in 9b0f24c74c80 Ign:1 http://mirrors.aliyun.com/debian wheezy InRelease Err:2 http://mirrors.aliyun.com/debian wheezy Release 404 Not Found [IP: 111.160.44.225 80] Reading package lists... E: The repository 'http://mirrors.aliyun.com/debian wheezy Release' does not have a Release file. The command '/bin/sh -c apt-get update' returned a non-zero code: 100 Unable to find image 'ladder/devtools:latest' locally docker: Error response from daemon: pull access denied for ladder/devtools, repository does not exist or may require 'docker login': denied: requested access to the resource is denied. See 'docker run --help'.
看了下是说好像是说镜像的问题
查了一下说是wheezy为debian(Linux发行版)的以前版本,因为Asp.Net Core5.0的docker镜像就是基于debian系统构建的,debian每个版本都有相对应的名字
- 5是Debian
- 6是squeeze
- 7是wheezy
- 8是jessie
- 9是stretch
那我们把镜像的系统改为最新的stretch,dockerfile如下
FROM mcr.microsoft.com/dotnet/sdk:5.0 RUN ln -s /lib/x86_64-linux-gnu/libdl-2.24.so /lib/x86_64-linux-gnu/libdl.so RUN echo "deb http://mirrors.aliyun.com/debian stretch main contrib non-free \ deb-src http://mirrors.aliyun.com/debian stretch main contrib non-free \ deb http://mirrors.aliyun.com/debian stretch-updates main contrib non-free \ deb-src http://mirrors.aliyun.com/debian stretch-updates main contrib non-free \ deb http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free \ deb-src http://mirrors.aliyun.com/debian-security stretch/updates main contrib non-free \ deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib \ deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib" > /etc/apt/sources.list # RUN apt-get update # RUN apt-get install -y --allow-unauthenticated libgdiplus libc6-dev libgdiplus libx11-dev && ln -s libgdiplus.so gdiplus.dll # RUN rm -rf /var/lib/apt/lists/* RUN apt-get update RUN apt-get install libgdiplus -y && ln -s libgdiplus.so gdiplus.dll COPY . /publish WORKDIR /publish EXPOSE 8801 CMD ["dotnet", "DevTools.dll", "--urls", "http://*:8801"]
可以看到已经成功启动,再看下验证码
已经成功识别了,因为我的图片不涉及中文,有中文的问题可以查看其他文章
这篇关于centos下.Netcore的docker容器部署出现“The type initializer for 'Gdip' threw an exception.”的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#
- 2024-01-24Advanced .Net Debugging 1:你必须知道的调试工具