我们配置了一个包含以下代码片段的Dockerfile:
#############################################
#### Image containing compiled libraries ####
#############################################
FROM php:8.2-fpm-bullseye AS builder
#######################################################
############# START ENVIRONMENT VARIABLES #############
# Versions
ENV MEMCACHE_VERSION=8.0 \
MEMCACHED_VERSION=3.2.0
############## END ENVIRONMENT VARIABLES ###############
########################################################
RUN apt-get update && apt-get install -y --no-install-recommends \
zlib1g-dev \
zlib1g \
libmemcached11 \
libmemcachedutil2 \
libmemcached-dev \
libmagickwand-dev
RUN pecl install memcache-$MEMCACHE_VERSION && \
pecl install memcached-$MEMCACHED_VERSION && \
pecl install imagick
#
# APPLICATION COMPILE
#
FROM ubuntu:20.04
LABEL maintainer='Timothy van Exel <[email protected]>'
#######################################################
################### START ARGUMENTS ##################
# Symfony environment type e.g. dev
ARG SYMFONY_ENV_NAME
#################### END ARGUMENTS ###################
#######################################################
#######################################################
############# START ENVIRONMENT VARIABLES #############
# Version
ENV UBUNTU_VERSION=20.04 \
PHP_VERSION=8.2 \
NODE_VERSION=14 \
COMPOSER_VERSION=2.5.4
# Folders
ENV APP_FOLDER=/var/www/html \
LOCAL_BIN_FOLDER=/usr/local/bin \
IMAGICK_FOLDER=/etc/ImageMagick-6 \
SO_FOLDER=/usr/local/lib/php/extensions/no-debug-non-zts-20220829 \
APACHE_CONF_FOLDER=/etc/apache2 \
SYMFONY_ENV=$SYMFONY_ENV_NAME
############## END ENVIRONMENT VARIABLES ###############
########################################################
WORKDIR $APP_FOLDER
RUN mkdir -p $SO_FOLDER && mkdir -p /var/log/supervisor && mkdir -p /var/run/apache && touch /var/log/supervisor/php-fpm_error.log && touch /var/log/supervisor/php-fpm.log
RUN touch /var/log/supervisor/apache2_error.log && touch /var/log/supervisor/apache2.log && chmod 777 -R /var/log/supervisor && chown www-data:www-data -Rf /var/log/supervisor
COPY --from=builder $SO_FOLDER/memcached.so /usr/lib/php/20220829/memcached.so
COPY --from=builder $SO_FOLDER/memcache.so /usr/lib/php/20220829/memcache.so
COPY --from=composer:2.5.4 /usr/bin/composer $LOCAL_BIN_FOLDER/composer
RUN apt-get update
RUN apt-get install lsb-release ca-certificates apt-transport-https software-properties-common -y
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git \
curl \
apache2 \
vim \
wget \
sudo \
memcached \
zlib1g-dev \
zlib1g \
libpng-dev \
libjpeg-dev \
libwebp-dev \
libzip-dev \
unzip \
zip \
ca-certificates \
libmagickwand-dev \
libmemcached11 \
libmemcachedutil2 \
libmemcached-dev \
libz-dev \
ghostscript \
gnupg \
supervisor \
ssh \
sshpass \
ansible \
php \
php$PHP_VERSION-fpm \
php-pear \
php$PHP_VERSION-dev \
php$PHP_VERSION-mysql \
php$PHP_VERSION-pdo \
php$PHP_VERSION-dom \
php$PHP_VERSION-gd \
php$PHP_VERSION-curl \
php$PHP_VERSION-zip \
php$PHP_VERSION-imagick \
php$PHP_VERSION-intl
#RUN a2enconf php$PHP_VERSION-fpm && a2enmod mpm_event proxy_fcgi setenvif rewrite
RUN a2enconf php$PHP_VERSION-fpm && a2dismod php8.3 mpm_prefork && a2enmod proxy proxy_fcgi setenvif rewrite
RUN apt-get install php8.2-fpm -y
RUN a2enmod mpm_event
RUN service php$PHP_VERSION-fpm start
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash \
&& export NVM_DIR="$HOME/.nvm" \
&& . $NVM_DIR/nvm.sh && nvm install $NODE_VERSION \
&& . $NVM_DIR/nvm.sh && nvm alias default $NODE_VERSION \
&& curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null \
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update && apt-get install yarn -y \
&& npm install -g [email protected] tributejs bootbox jquery-flagstrap i18next bootstrap@5 less less-loader less-plugin-clean-css webpack yaml-loader webpack-cli js-cookie [email protected] jquery-ui blueimp-file-upload jquery-ui-dist jquery-textcomplete @popperjs/core linkify-html linkifyjs @symfony/webpack-encore @babel/core @babel/cli @babel/preset-env lightbox2 uglify-js less dotenv
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
COPY ../pipeline/$SYMFONY_ENV/config/php/ini_files/* /etc/php/$PHP_VERSION/fpm/conf.d/
COPY ../pipeline/$SYMFONY_ENV/config/php/ini_files/* /etc/php/$PHP_VERSION/cli/conf.d/
COPY ../pipeline/$SYMFONY_ENV/config/php/policy.xml $IMAGICK_FOLDER/policy_improved.xml
COPY ../pipeline/$SYMFONY_ENV/config/supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY ../pipeline/$SYMFONY_ENV/config/apache/000-default.conf $APACHE_CONF_FOLDER/sites-available/000-default.conf
COPY ../pipeline/scripts/web_entrypoint.sh $LOCAL_BIN_FOLDER/web_entrypoint
RUN chmod +x $LOCAL_BIN_FOLDER/web_entrypoint
EXPOSE 80
CMD ["web_entrypoint"]
dockerfile 也可以在这里查看:https://docs.google.com/document/d/1bd2a_LtwIrgb8vRMzoIf0gBQgp6RxEZHQauTZAppOFc/edit?usp=sharing
但在 1 月 11 日星期四,从 21:00 开始运行docker compose up --build
-d --force-recreate 后,突然出现以下错误。注意:本周早些时候没有发生这种情况,整个星期它都运行正常。
=> CACHED [webserver stage-1 11/21] RUN apt-get update && DEBIAN_FRONTEND=noninteractive a 0.0s
=> ERROR [webserver stage-1 12/21] RUN a2enconf php8.2-fpm && a2enmod mpm_event proxy_fcgi 0.2s
------
> [webserver stage-1 12/21] RUN a2enconf php8.2-fpm && a2enmod mpm_event proxy_fcgi setenvif rewrite:
0.129 Enabling conf php8.2-fpm.
0.131 To activate the new configuration, you need to run:
0.131 service apache2 reload
0.146 ERROR: Module mpm_prefork is enabled - cannot proceed due to conflicts. It needs to be disabled first!
0.146 Considering conflict mpm_worker for mpm_event:
0.146 Considering conflict mpm_prefork for mpm_event:
0.146 Considering dependency proxy for proxy_fcgi:
0.146 Enabling module proxy.
0.148 Enabling module proxy_fcgi.
0.150 Module setenvif already enabled
0.150 Enabling module rewrite.
0.152 To activate the new configuration, you need to run:
0.152 service apache2 restart
------
failed to solve: process "/bin/sh -c a2enconf php$PHP_VERSION-fpm && a2enmod mpm_event proxy_fcgi setenvif rewrite" did not complete successfully: exit code: 1
看起来 mpm_event 出了点问题。我想重申一下,我们没有更改 Dockerfile 中的任何内容。
我们已经尝试过的:
- 删除 mpm_event,构建成功,但应用程序逻辑上不起作用,因为它需要 mpm_event
- 更新 Docker Desktop
- 禁用 mpm_prefork 后出现以下错误:
ERROR: The following modules depend on mpm_prefork and need to be disabled first: php8.3
答案1
罪魁祸首是软件包php
,它会拉动 apache 模块,而该模块默认被激活并启用该mpm_prefork
模块。
如果您只使用 php-fpm,则根本不需要它。该php-fpm
包会自行安装所需的一切。
或者您只是禁用 php 模块和 mpm_prefork 模块。