无法在 Dockerfile 中添加 PPA ondrej\PHP

Mor*_*ogt 1 php apache docker dockerfile

我想用 PHP 和一些 PHP 模块扩展 httpd 图像。我的 Dockerfile 看起来像这样。

\n
FROM httpd:2.4                                 \n                                           \nCOPY forma.conf /etc/apache2/sites-available/  \n                                           \nRUN apt-get update && apt-get install -y \\     \n    nano \\                                     \n    software-properties-common   \n\nRUN LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php           \n                                                                                          \nRUN apt-get -y update && apt-get install -y \\  \n    php7.2 \\                               \n    libapache2-mod-php7.2 \\                \n    php7.2-common \\                        \n    php7.2-mysql \\                         \n    php7.2-gmp \\                           \n    php7.2-ldap \\                          \n    php7.2-curl \\                          \n    php7.2-intl \\                          \n    php7.2-mbstring \\                      \n    php7.2-xmlrpc \\                        \n    php7.2-gd \\                            \n    php7.2-bcmath \\                        \n    php7.2-xml \\                           \n    php7.2-cli \\                           \n    php7.2-zip        \n
Run Code Online (Sandbox Code Playgroud)\n

我在构建图像时遇到的错误如下泊坞窗错误

\n

我\xc2\xb4m 做错了什么?

\n

编辑:\n感谢@RJK\n在步骤 5/6 中,您正在运行 add-apt-repository -y ppa:ondrej\\php,它应该是 add-apt-repository -y ppa:ondrej/php (正斜杠)

\n

现在脚本可以找到 ppa,但出现另一个错误。\n在此输入图像描述

\n

Fre*_*dia 5

httpd 镜像基于 Debian,ondrej 存储库是为 Ubuntu 设计的,两者相关,但会给您带来问题。

当 add-apt-repository 运行时,它会添加适合您当前系统版本的 PPA,httpd 映像使用 Debian buster,它相当于尚未发布的 Ubuntu hirsute (21.04),并且 PPA 中没有相应的软件包。您可以通过手动导入并指定 ubuntu 版本(在本例中为 groovy)来解决此问题:

RUN apt-get update && apt-get install gpg && echo -n 'deb http://ppa.launchpad.net/ondrej/php/ubuntu groovy main' > /etc/apt/sources.list.d/ondrej-ubuntu-php-groovy.list && \
        apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C
Run Code Online (Sandbox Code Playgroud)

然而,你只会遇到更多的问题。我建议从 Ubuntu 基础开始并安装您需要的一切:

FROM ubuntu:20.04

RUN apt-get update && apt-get install -y software-properties-common

RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php

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

RUN apt-get update -y && apt-get install -y php7.2 \
    libapache2-mod-php7.2 \
    php7.2-common \
    php7.2-mysql \
    php7.2-gmp \
    php7.2-ldap \
    php7.2-curl \
    php7.2-intl \
    php7.2-mbstring \
    php7.2-xmlrpc \
    php7.2-gd \
    php7.2-bcmath \
    php7.2-xml \
    php7.2-cli \
    php7.2-zip
Run Code Online (Sandbox Code Playgroud)
Sending build context to Docker daemon  4.608kB
Step 1/5 : FROM ubuntu:20.04
 ---> f63181f19b2f
Step 2/5 : RUN apt-get update && apt-get install -y software-properties-common
 ---> Running in 375ea87dedcf
[snip]
 ---> 01f569d22228
Removing intermediate container 375ea87dedcf
Step 3/5 : RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
 ---> Running in b28c033f910c
[snip]
 ---> cbc543280aac
Removing intermediate container b28c033f910c
Step 4/5 : RUN apt-get update -y && apt-get install -y apache2
 ---> Running in 63de13b5676e
[snip]
 ---> 917b1cdcd5c3
Removing intermediate container 63de13b5676e
Step 5/5 : RUN apt-get update -y && apt-get install -y php7.2     libapache2-mod-php7.2     php7.2-common     php7.2-mysql     php7.2-gmp     php7.2-ldap     php7.2-curl     php7.2-intl     php7.2-mbstring     php7.2-xmlrpc     php7.2-gd     php7.2-bcmath     php7.2-xml     php7.2-cli     php7.2-zip
 ---> Running in fe46743f3534
[snip]
 ---> ce93f9470361
Removing intermediate container fe46743f3534
Successfully built ce93f9470361
Run Code Online (Sandbox Code Playgroud)

值得注意的是,PPA 描述中有关于设置正确区域设置的警告,应该是:LC_ALL=C.UTF-8