Docker php 的 Centos 无法启动
Docker Centos with php fails to start
我正在尝试构建一个带有 php 的 centos 服务器
我正在使用 centos:7 图像并在其中安装 php 依赖项。
但这似乎并不是每次都有效,构建成功但容器关闭之后。
这是我的docker-compose.yml
version: "3.7"
services:
server:
build:
context: ./.docker
volumes:
- ./src/:/opt/app-root/src
ports:
- "9000:9000"
networks:
default:
external:
name: network_rp
和 Dockerfile(在 .docker/Dokerfile 中找到):
FROM centos:7
# Ajout des repo utiles
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm \
&& rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# Installation des packages
RUN yum-config-manager --enable remi-php73 \
&& yum install -y git zip unzip \
php php-intl php-opcache php-mbstring php-dom \
php-pdo php-mysqlnd php-pecl-xdebug php-soap \
php-bcmath php-zip php-ast php-fpm
RUN yum update -y
# Parametrage PHP
RUN echo 'date.timezone=Europe/Paris' > /etc/php.d/00-docker-php-date-timezone.ini
# Installation composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
# xdebug.ini. Activer les directives selon les besoins
RUN echo 'xdebug.remote_enable=1' >> /etc/php.d/15-xdebug.ini \
&& echo 'xdebug.remote_connect_back=0' >> /etc/php.d/15-xdebug.ini \
&& echo "xdebug.remote_host=127.0.0.1" >> /etc/php.d/15-xdebug.ini \
&& echo 'xdebug.remote_autostart=1' >> /etc/php.d/15-xdebug.ini \
&& echo 'xdebug.remote_log=/opt/app-root/src/var/logs/xdebug.log' >> /etc/php.d/15-xdebug.ini
# Vide le dossier temporaire
RUN rm -rf /tmp/*
WORKDIR /opt/app-root/src
CMD ["php-fpm"]
EXPOSE 9000
有什么想法吗?
这里有2个问题:
1. /var/run/php-fpm/
丢失,那么您将遇到下一个错误:
[18-Mar-2021 06:12:09] ERROR: Unable to create the PID file (/run/php-fpm/php-fpm.pid).: No such file or directory (2)
[18-Mar-2021 06:12:09] ERROR: FPM initialization failed
因此,您需要在 CMD ["php-fpm"]
之前添加下一行:
RUN mkdir -p /var/run/php-fpm
2。你需要在前台make php-fpm 运行,使用next,看例子here:
CMD [ "php-fpm", "-F" ]
我正在尝试构建一个带有 php 的 centos 服务器 我正在使用 centos:7 图像并在其中安装 php 依赖项。 但这似乎并不是每次都有效,构建成功但容器关闭之后。
这是我的docker-compose.yml
version: "3.7"
services:
server:
build:
context: ./.docker
volumes:
- ./src/:/opt/app-root/src
ports:
- "9000:9000"
networks:
default:
external:
name: network_rp
和 Dockerfile(在 .docker/Dokerfile 中找到):
FROM centos:7
# Ajout des repo utiles
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm \
&& rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# Installation des packages
RUN yum-config-manager --enable remi-php73 \
&& yum install -y git zip unzip \
php php-intl php-opcache php-mbstring php-dom \
php-pdo php-mysqlnd php-pecl-xdebug php-soap \
php-bcmath php-zip php-ast php-fpm
RUN yum update -y
# Parametrage PHP
RUN echo 'date.timezone=Europe/Paris' > /etc/php.d/00-docker-php-date-timezone.ini
# Installation composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
# xdebug.ini. Activer les directives selon les besoins
RUN echo 'xdebug.remote_enable=1' >> /etc/php.d/15-xdebug.ini \
&& echo 'xdebug.remote_connect_back=0' >> /etc/php.d/15-xdebug.ini \
&& echo "xdebug.remote_host=127.0.0.1" >> /etc/php.d/15-xdebug.ini \
&& echo 'xdebug.remote_autostart=1' >> /etc/php.d/15-xdebug.ini \
&& echo 'xdebug.remote_log=/opt/app-root/src/var/logs/xdebug.log' >> /etc/php.d/15-xdebug.ini
# Vide le dossier temporaire
RUN rm -rf /tmp/*
WORKDIR /opt/app-root/src
CMD ["php-fpm"]
EXPOSE 9000
有什么想法吗?
这里有2个问题:
1. /var/run/php-fpm/
丢失,那么您将遇到下一个错误:
[18-Mar-2021 06:12:09] ERROR: Unable to create the PID file (/run/php-fpm/php-fpm.pid).: No such file or directory (2)
[18-Mar-2021 06:12:09] ERROR: FPM initialization failed
因此,您需要在 CMD ["php-fpm"]
之前添加下一行:
RUN mkdir -p /var/run/php-fpm
2。你需要在前台make php-fpm 运行,使用next,看例子here:
CMD [ "php-fpm", "-F" ]