在运行Docker时,安装PHP8.1时出现错误。

3

我在我的Laravel项目中使用Docker,但是在安装PHP时遇到了错误。

我已经用相同的配置运行过该项目一次,并且没有出现任何问题。

错误:

=> ERROR [14/26] RUN apt-get install -y     php8.1-fpm     php8.1-common     php8.1-curl     php8.1-mysql     php8.1-mbstring     php8.1-xml     php8.1-bcmath     php8.1-gd     php8.1-xdebug     php8.1-soap     php8  2.3s 
------
 > [14/26] RUN apt-get install -y     php8.1-fpm     php8.1-common     php8.1-curl     php8.1-mysql     php8.1-mbstring     php8.1-xml     php8.1-bcmath     php8.1-gd     php8.1-xdebug     php8.1-soap     php8.1-zip:       
#18 0.621 Reading package lists...
#18 1.822 Building dependency tree...
#18 2.008 Reading state information...
#18 2.106 Some packages could not be installed. This may mean that you have
#18 2.106 requested an impossible situation or if you are using the unstable
#18 2.106 distribution that some required packages have not yet been created
#18 2.106 or been moved out of Incoming.
#18 2.106 The following information may help to resolve the situation:
#18 2.106
#18 2.106 The following packages have unmet dependencies:
#18 2.255  php8.1-fpm : Depends: systemd but it is not going to be installed or
#18 2.255                        systemd-tmpfiles but it is not installable
#18 2.275 E: Unable to correct problems, you have held broken packages.
------
executor failed running [/bin/sh -c apt-get install -y     php8.1-fpm     php8.1-common     php8.1-curl     php8.1-mysql     php8.1-mbstring     php8.1-xml     php8.1-bcmath     php8.1-gd     php8.1-xdebug     php8.1-soap  
   php8.1-zip]: exit code: 100

我的Dockerfile:
#------------- Setup Environment -------------------------------------------------------------

# Pull base image
FROM ubuntu:18.04
ENV TZ=America/Sao_Paulo
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Install common tools 
RUN apt-get update
RUN apt-get install -y wget curl nano htop git unzip bzip2 software-properties-common locales

# Set evn var to enable xterm terminal
ENV TERM=xterm

# Set working directory
WORKDIR /var/www/html

COPY . ./

# Add repositories
RUN LC_ALL=C.UTF-8 apt-add-repository ppa:ondrej/php
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C
RUN echo "deb http://nginx.org/packages/ubuntu/ trusty nginx" >> /etc/apt/sources.list
RUN echo "deb-src http://nginx.org/packages/ubuntu/ trusty nginx" >> /etc/apt/sources.list

RUN apt-get update

#------------- Application Specific Stuff ----------------------------------------------------

# Install PHP
RUN apt-get update
RUN apt-get install -y \
    php8.1-fpm \ 
    php8.1-common \ 
    php8.1-curl \ 
    php8.1-mysql \ 
    php8.1-mbstring \ 
    php8.1-xml \
    php8.1-bcmath \
    php8.1-gd \
    php8.1-xdebug \
    php8.1-soap \
    php8.1-zip   

RUN echo "xdebug.mode=develop" >> /etc/php/8.1/mods-available/xdebug.ini

#------------- FPM & Nginx configuration ----------------------------------------------------

# Config fpm to use TCP instead of unix socket
ADD docker/www.conf /etc/php/8.1/fpm/pool.d/www.conf
RUN mkdir -p /var/run/php

# Install Nginx
RUN apt-get install -y nginx

ADD docker/game /etc/nginx/sites-enabled/

ADD docker/nginx.conf /etc/nginx/

#------------- Composer & laravel configuration ----------------------------------------------------

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

#------------- Supervisor Process Manager ----------------------------------------------------

# Install supervisor
RUN apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
ADD docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

#------------- Container Config ---------------------------------------------------------------
ARG ENV_KEY=dev

COPY ./.${ENV_KEY}.env ./.env

RUN chown -R www-data:www-data ./

# Expose port 80
EXPOSE 80

# Set supervisor to manage container processes
ENTRYPOINT ["/usr/bin/supervisord"]

我已经通过docker system prune -a清除了docker的设置。我还卸载并重新安装了docker。

您有什么建议可以解决这个问题吗?


1
只是为了尝试一下,在第一个“RUN apt-get install -y .....”后面添加systemd(在locales之后),并告诉我们发生了什么。 - matiaslauriti
“FROM ubuntu:18.04” 看起来对我来说有点旧了 - 为什么不使用最新的镜像呢? - Nico Haase
1个回答

1
自8月2日以来,我遇到了同样的问题,看起来是ondrej/php存储库出了问题。首先,我尝试按照@matiaslauriti的建议安装systemd,但是出现了以下错误:
The following packages have unmet dependencies:
[07:33:33]#24 7.480  systemd : Depends: libsystemd0 (= 237-3ubuntu10.53) but 237-3ubuntu10.54 is to be installed

通过将以下内容添加到 sources.list 中,该问题已得到解决:

RUN echo "deb http://archive.ubuntu.com/ubuntu/ bionic-proposed main" >> /etc/apt/sources.list

您不需要显式安装 systemd,它会作为 php 的一个依赖项自动安装。


“看起来好像有些问题” - 那为什么不在 https://github.com/oerdnj/deb.sury.org/issues 提交到错误跟踪器中呢? - Nico Haase
@NicoHaase,我需要快速修复这个错误,为什么你不自己发布错误报告呢? - cheack
我没有遇到任何问题,但你可能有 :) 解决这个问题也可以帮助其他人。这是一件好事,因为你正在使用其他人(如Ondrej)免费为他人管理的东西。 - Nico Haase

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接