关于.net core 3.0 docker 部署 System.Drawing.Common 的问题

问题:

  .net core 3.0 使用 mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim 作为基础镜像,在开发中用到了绘图的功能,跑起来发现缺少 libgdiplus

解决方案:

  参考:https://q.cnblogs.com/q/109061/

  只需要在容器中安装 libgdiplus libc6-dev 即可成功。

思考:

  一个项目中用到直接解决即可,当多个项目中用到每次都去安装那真是要崩溃...有什么解决方案呢?

解决:

  自己做一个带gdi+的基础镜像不就好了,dockerfile 也很简单:

  ******************************Dockerfile**********************************

  FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim

  RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free \
  deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free \
  deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free \
  deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free \
  " > /etc/apt/sources.list

  RUN apt-get update
  RUN apt-get install -y --no-install-recommends libgdiplus libc6-dev

  ******************************Dockerfile**********************************

  第二行是添加清华大学的源,用官方源人品就是success,人品不好就是 Unable to locate package xxx(开玩笑,网络实在是...)

  docker build -t mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-gdi .

  完美,需要绘图的就基于这个镜像就可以了。

 

posted @   whyfate  阅读(650)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示