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

.NET 8升级后Docker环境下wkhtmltopdf安装失败求助

问题:.NET 8升级后Docker中wkhtmltopdf安装失败

将Web应用从.NET 6升级到.NET 8后,构建Docker镜像时出现如下错误:

Severity   Code    Description Project File    Line    Suppression State Error   DT1001  failed to solve: process "/bin/sh -c apt-get install -y --no-install-recommends zlib1g fontconfig libfreetype6 libx11-6 libxext6 libxrender1 wget gdebi" did not complete successfully: exit code: 100 If the error persists, try restarting Docker Desktop.   docker-compose  C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets    425  

原Dockerfile内容:

FROM mcr.microsoft.com/dotnet/sdk:8.0 as base
WORKDIR /app
# RUN echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
    && rm -rf /var/lib/apt/lists/*

RUN apt-get update && apt-get install -y --no-install-recommends libgdiplus \
    && rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/lib/libgdiplus.so /lib/x86_64-linux-gnu/libgdiplus.so
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        zlib1g \
        fontconfig \
        libfreetype6 \
        libx11-6 \
        libxext6 \
        libxrender1 \
        xfonts-75dpi \
        xfonts-base \
        wget \
        gdebi \
    && rm -rf /var/lib/apt/lists/*
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.stretch_amd64.deb
RUN gdebi --n wkhtmltox_0.12.5-1.stretch_amd64.deb
# mlm - I question the validity of using the libssl1.0-dev
# package below. The docs say this: "This is a transition package that will go away after the stretch release to provide the 1.0.X APIs for those packages that are not ready for the 1.1 version yet."
# https://packages.debian.org/stretch/libssl1.0-dev
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    libssl1.1 \
    && rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/local/lib/libwkhtmltox.so /usr/lib/libwkhtmltox.so

修改建议

问题核心:.NET 8官方镜像基于Debian 12(Bookworm),原Dockerfile使用的wkhtmltopdf 0.12.5是为Debian 9(Stretch)编译的,依赖库版本不兼容导致apt安装失败。以下是针对性修改:

  • 替换wkhtmltopdf为兼容Debian 12的版本:使用wkhtmltopdf 0.12.6(官方支持Debian 12)替代旧版本,彻底解决依赖冲突。
  • 用dpkg替代gdebi处理deb包:gdebi在新版本Debian中存在依赖解析问题,改用dpkg -i配合apt-get -f install自动修复依赖链。
  • 合并apt命令减少镜像层数:将多次apt-get update合并,减少构建时间和镜像体积。
  • 移除冗余的libssl依赖:Debian 12默认使用libssl3,无需安装libssl1.1。

修改后的Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:8.0 as base
WORKDIR /app

# 合并安装所有基础依赖,减少镜像层数
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    libgdiplus \
    zlib1g \
    fontconfig \
    libfreetype6 \
    libx11-6 \
    libxext6 \
    libxrender1 \
    xfonts-75dpi \
    xfonts-base \
    wget \
    && rm -rf /var/lib/apt/lists/*

# 修复libgdiplus系统链接
RUN ln -s /usr/lib/libgdiplus.so /lib/x86_64-linux-gnu/libgdiplus.so

# 下载并安装兼容Debian 12的wkhtmltopdf
RUN wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.6/wkhtmltox_0.12.6-1.bookworm_amd64.deb \
    && dpkg -i wkhtmltox_0.12.6-1.bookworm_amd64.deb \
    && apt-get install -y -f --no-install-recommends \
    && rm -rf wkhtmltox_0.12.6-1.bookworm_amd64.deb /var/lib/apt/lists/*

# 设置wkhtmltopdf库系统链接
RUN ln -s /usr/local/lib/libwkhtmltox.so /usr/lib/libwkhtmltox.so

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 06:08:16