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

Laradock php-fpm服务构建失败求助:Ubuntu16.04下依赖包安装报错

Fixing "Unable to correct problems, you have held broken packages" in Laravel Docker Build

Hey there! Let's work through why your php-fpm Docker build is throwing that frustrating broken packages error. First, let's recap your setup to make sure we're aligned:

  • Operating System: Ubuntu 16.04
  • Docker Version: 20.10.6
  • Commit Hash: 63fc1fd
  • Project Versions: Laravel 5.8.33, Vue 2.6.10

The Core Issue

The biggest culprit here is that Ubuntu 16.04 (Xenial Xerus) reached End-of-Life (EOL) back in April 2021. The official Ubuntu repositories (archive.ubuntu.com and security.ubuntu.com) no longer host packages for this version. When your Docker image runs apt-get update, it can't pull valid package lists, which leads to missing dependencies and the "held broken packages" error when trying to install libzip-dev and other tools.

Solutions to Try

1. Switch APT Sources to Ubuntu's Old Releases Mirror

If you need to stick with the Ubuntu 16.04-based php-fpm image, you'll need to update the APT sources to point to Ubuntu's archive for retired versions. Add these lines to your Dockerfile before any apt-get update commands:

# Replace deprecated Ubuntu 16.04 APT sources with old-releases mirror
RUN sed -i -e 's/archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list && \
    sed -i -e 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

Then tweak your installation command to include --fix-missing to resolve any lingering dependency conflicts:

RUN set -xe; \
    apt-get update -yqq && \
    pecl channel-update pecl.php.net && \
    apt-get install -yqq --fix-missing apt-utils libzip-dev zip unzip && \
    docker-php-ext-configure zip --with-libzip && \
    docker-php-ext-install zip && \
    php -m | grep -q 'zip'

2. Upgrade to a Supported Base Image (Recommended)

A more sustainable fix is to switch to a supported php-fpm base image. Laravel 5.8 requires PHP 7.1 or higher, so you can use a Debian-based image (like php:7.2-fpm-bullseye) or a newer Ubuntu version (like php:7.2-fpm-focal for Ubuntu 20.04). These images have active repositories, so you won't run into broken package issues at all.

For example, update your Dockerfile's base image line:

# Use a supported Debian-based PHP image compatible with Laravel 5.8
FROM php:7.2-fpm-bullseye

You can keep your original installation commands as-is here—no need to modify APT sources, since the repositories are still maintained.

Why This Works

When Ubuntu versions go EOL, their packages are moved to old-releases.ubuntu.com to free up space on main repositories. Switching to this mirror lets your Docker image fetch the packages it needs. Upgrading to a supported base image eliminates this problem entirely and ensures you get security updates for your runtime environment.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 18:57:33