Azure Function App Docker构建失败,报'usrmerge'错误
Root Cause
Your build is failing because you've added Debian Trixie (testing) repository to a base image based on Debian Bullseye (stable). Trixie uses a merged /usr filesystem by default, and one of the packages you're installing from Trixie now depends on usr-is-merged—a package that enforces the merged /usr setup. The base Azure Functions image doesn't use merged /usr, leading to a conflict. Installing usrmerge won't resolve this because converting to merged /usr in a Docker build requires modifying core filesystem structures, which the base image isn't configured to handle.
Solutions
1. Remove the Trixie Repository
The simplest fix is to eliminate the Trixie repo entry, since mixing stable and testing repos is prone to dependency conflicts. Update your Dockerfile to remove the Trixie line:
FROM mcr.microsoft.com/azure-functions/python:4-python3.9 AS prod-image ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ AzureFunctionsJobHost__Logging__Console__IsEnabled=true RUN echo "deb https://security.debian.org/debian-security stable-security/updates main" >> /etc/apt/sources.list && \ echo "deb https://deb.debian.org/debian bullseye main contrib non-free" >> /etc/apt/sources.list && \ apt-get update && apt-get install -y \ poppler-data \ poppler-utils \ build-essential \ libpq-dev \ libpq5 \ python3-cryptography \ python3-dev \ libc6-dev \ ghostscript \ libgs10 \ libgs10-common \ tesseract-ocr
This ensures all packages are pulled from Bullseye and its security updates, which are compatible with the base image's filesystem setup.
2. Switch to a Base Image with Merged /usr
If you specifically need packages from Trixie, switch to an Azure Functions base image built on a newer Debian release that uses merged /usr (like Bookworm or Trixie). Check Microsoft's available tags for Azure Functions Python images to find a suitable version. For example:
FROM mcr.microsoft.com/azure-functions/python:4-python3.9-bookworm AS prod-image # Rest of your Dockerfile remains similar, adjust repository entries if needed for the new base image
3. Pin Packages to Bullseye (Advanced)
If you must keep the Trixie repo but avoid the dependency conflict, use apt pinning to prioritize Bullseye packages over Trixie ones. Add these lines before your apt-get update command:
RUN echo "Package: *" >> /etc/apt/preferences.d/bullseye-pin && \ echo "Pin: release n=bullseye" >> /etc/apt/preferences.d/bullseye-pin && \ echo "Pin-Priority: 900" >> /etc/apt/preferences.d/bullseye-pin && \ echo "Package: *" >> /etc/apt/preferences.d/trixie-pin && \ echo "Pin: release n=trixie" >> /etc/apt/preferences.d/trixie-pin && \ echo "Pin-Priority: 100" >> /etc/apt/preferences.d/trixie-pin
This configuration ensures Bullseye packages are selected by default. If you need specific packages from Trixie, you can adjust their pin priority individually. Note that this approach can lead to unexpected issues if package dependencies are complex.
The sudden failure is likely due to recent updates in Trixie's package dependencies that now require usr-is-merged, which wasn't the case when your build worked in November 2023.
内容的提问来源于stack exchange,提问作者krish

