如何使用 php7.4-apache docker 映像将 apache 升级到最新版本

How to upgrade apache to the latest version using the php7.4-apache docker image

我在官方 PHP docker 图像 (https://hub.docker.com/_/php) 上有一个网站 运行 使用 php7.4-apache.

现阶段我无法升级到PHP 8,所以我想暂时尽可能坚持这个设置。此映像随 Apache 2.4.48 一起提供,我需要安装最新版本以修补现有的安全问题。

我还没有在任何地方看到这个记录。这是我起床的地方:

FROM php:7.4-apache

RUN apt-get -y update
RUN apt-get install software-properties-common -y
RUN apt-get install -y gnupg
RUN apt-get install -y ca-certificates
#RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys  4F4EA0AAE5267A6C

RUN add-apt-repository ppa:ondrej/apache2 -y && sudo apt update

请注意,我尝试使用和不使用 apt-key 行,最后我得到:

Step 6/27 : RUN add-apt-repository ppa:ondrej/apache2 -y && sudo apt update
 ---> Running in 9fa3694a2c5b
gpg: keybox '/tmp/tmpzx1fa6uo/pubring.gpg' created
gpg: /tmp/tmpzx1fa6uo/trustdb.gpg: trustdb created
gpg: key 4F4EA0AAE5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg:               imported: 1
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
gpg: no valid OpenPGP data found.
/bin/sh: 1: sudo: not found

更新: 删除 sudo 后,出现此错误

Hit:1 deb.debian.org/debian bullseye InRelease 
Get:3 security.debian.org/debian-security bullseye-security InRelease [44.1 kB] 
Ign:4 ppa.launchpad.net/ondrej/apache2/ubuntu jammy InRelease 
Err:6 ppa.launchpad.net/ondrej/apache2/ubuntu jammy Release 404 Not Found 
[IP: 91.189.95.85 80] Reading package lists... 
E: The repository 'ppa.launchpad.net/ondrej/apache2/ubuntu jammy Release' does not have a Release file.

如有任何帮助,我们将不胜感激!

在最后一行中,您使用的是默认情况下未安装的 sudo。删除它应该可以解决您的错误。您的 Dockerfile 将如下所示。

FROM php:7.4-apache

RUN apt-get -y update
RUN apt-get install software-properties-common -y
RUN apt-get install -y gnupg
RUN apt-get install -y ca-certificates
#RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys  4F4EA0AAE5267A6C

RUN add-apt-repository ppa:ondrej/apache2 -y && apt update

我在这里找到了解决问题的方法:https://gist.github.com/ianacid/4ee1b2b7705efc6aba25ab2f3976f62f

我们首先加载新资源:

# deb http://snapshot.debian.org/archive/debian/20210621T000000Z buster main
deb http://deb.debian.org/debian buster main
# deb http://snapshot.debian.org/archive/debian-security/20210621T000000Z buster/updates main
deb http://security.debian.org/debian-security buster/updates main
# deb http://snapshot.debian.org/archive/debian/20210621T000000Z buster-updates main
deb http://deb.debian.org/debian buster-updates main
deb http://ftp.ch.debian.org/debian sid main

将它们复制到 docker 图像中并 运行 更新:

COPY ./sources.list /etc/apt/sources.list  

RUN apt-get update && apt-get install apache2 -y