在 Docker 容器中运行 .NET 6 并使用 libgdiplus(通常是为了支持 System.Drawing.Common 进行图片处理),你需要完成以下两个核心步骤
- 修改项目文件(.csproj)
从 .NET 6 开始,System.Drawing.Common 默认不再支持非 Windows 平台。你需要手动在项目的 .csproj 文件中添加配置来启用 Unix 支持:
- 编写 Dockerfile
在你的 Dockerfile 中,需要基于官方的 .NET 6 镜像,并通过 apt-get 安装 libgdiplus 及其依赖。
以下是一个标准的 Dockerfile 示例:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
更新包管理器并安装 libgdiplus 和 libc6-dev
替换为国内镜像源(以 Debian 为例)
RUN echo "deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib" > /etc/apt/sources.list
&& echo "deb https://mirrors.aliyun.com/debian-security/ bullseye-security main" >> /etc/apt/sources.list
&& echo "deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib" >> /etc/apt/sources.list
&& apt-get update -y
&& apt-get install -y libgdiplus libc6-dev
&& apt-get clean
&& ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
COPY . /app
ENTRYPOINT ["dotnet", "WebApi.dll"]
作者:过错
出处:http://www.cnblogs.com/wang2650/
关于作者:net开发做的久而已。十余年时光虚度!
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题,可以邮件:wang2650@163.com
联系我,非常感谢。

浙公网安备 33010602011771号