You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6升级至.NET 8后Dockerfile安装msttcorefonts-installer报错求助

解决.NET 8 Alpine镜像中安装微软字体的SSL连接错误

问题描述

将.NET 6环境下正常运行的Dockerfile升级到.NET 8后,执行微软字体安装命令时出现SSL连接失败:

RUN apk --no-cache add msttcorefonts-installer fontconfig && \
    update-ms-fonts && \
    fc-cache -f

报错信息:

OpenSSL: error:0A000126:SSL routines::unexpected eof while reading. Unable to establish SSL connection. Connecting to ufpr.dl.sourceforge.net (ufpr.dl.sourceforge.net)|2801:82:80ff:13:ba59:9fff:fe86:2dd0|:443... failed: Network unreachable...

原因分析

  1. .NET 8的Alpine镜像基于更高版本的Alpine系统(如3.18),其默认网络工具(curl/openssl)对SSL协议的兼容性设置有变化,导致部分SourceForge镜像节点连接失败。
  2. 容器环境默认优先使用IPv6连接,但多数环境未配置IPv6支持,导致尝试连接SourceForge的IPv6地址时出现"Network unreachable"错误。

解决方案

方案一:强制使用IPv4连接

在执行update-ms-fonts前设置环境变量,强制curl使用IPv4解析地址,绕过IPv6连接问题:

RUN apk --no-cache add msttcorefonts-installer fontconfig && \
    export CURL_IPRESOLVE=v4 && \
    update-ms-fonts && \
    fc-cache -f -v

方案二:改用第三方字体镜像安装

如果SourceForge源持续不稳定,可直接从GitHub镜像下载微软字体包,替代官方的安装脚本:

RUN apk --no-cache add fontconfig wget unzip && \
    # 下载GitHub上维护的微软字体包
    wget -O msfonts.zip https://github.com/imchenglibin/msfonts/archive/refs/heads/master.zip && \
    unzip msfonts.zip && \
    # 安装字体到系统目录
    mkdir -p /usr/share/fonts/msfonts && \
    cp msfonts-master/*.ttf /usr/share/fonts/msfonts/ && \
    # 更新字体缓存
    fc-cache -f -v && \
    # 清理临时文件
    rm -rf msfonts.zip msfonts-master

方案三:更换Alpine软件源

将Alpine默认源替换为国内镜像源(如阿里云),提升软件包和依赖的下载稳定性:

# 替换为阿里云Alpine源(对应.NET 8镜像使用的Alpine 3.18版本)
RUN echo "https://mirrors.aliyun.com/alpine/v3.18/main/" > /etc/apk/repositories && \
    echo "https://mirrors.aliyun.com/alpine/v3.18/community/" >> /etc/apk/repositories && \
    # 安装字体工具并更新字体
    apk --no-cache add msttcorefonts-installer fontconfig && \
    update-ms-fonts && \
    fc-cache -f -v

验证方法

安装完成后,可执行以下命令确认字体是否成功安装:

fc-list | grep "Microsoft"

内容的提问来源于stack exchange,提问作者Jayne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 19:07:10