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

如何在Python Azure Function Docker容器中安装pdfkit/wkhtmltopdf?

解决Azure Function Docker镜像中安装wkhtmltopdf的问题

你的基础镜像mcr.microsoft.com/azure-functions/python:3.0-python3.8基于Debian系统,而你看到的示例用的是Alpine系统的apk包管理器,不能直接照搬。需要用Debian的apt-get来安装wkhtmltopdf,以下是修改后的完整Dockerfile:

FROM mcr.microsoft.com/azure-functions/python:3.0-python3.8

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

# 更新apt源并安装wkhtmltopdf,安装后清理缓存减小镜像体积
RUN apt-get update && \
    apt-get install -y --no-install-recommends wkhtmltopdf && \
    rm -rf /var/lib/apt/lists/*

COPY requirements.txt /
RUN pip install -r /requirements.txt

COPY . /home/site/wwwroot

关键说明:

  • 先执行apt-get update更新软件源,确保能找到wkhtmltopdf包
  • --no-install-recommends参数避免安装不必要的依赖,减少镜像大小
  • 安装完成后用rm -rf /var/lib/apt/lists/*清理apt缓存,进一步减小镜像体积
  • 确保你的requirements.txt中已经添加了pdfkit

这样修改后,Docker镜像会同时安装Python依赖和wkhtmltopdf,pdfkit就能正常调用wkhtmltopdf渲染PDF了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 02:30:48