这是我的 Dockerfile,用于创建基于 CentOS 8 的简单 Web 服务器:
FROM centos:8
RUN yum -y update && \
yum -y install httpd php
COPY . /var/www/html
CMD ["httpd", "-D", "FOREGROUND"]
我使用以下命令构建并运行容器:docker build -t web .
docker run --rm --name web -p 8000:80 --network net1 --mount type=bind,source=`pwd`,target=/var/www/html web
我在访问 http://localhost:8000 时看到的错误是:Service Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
httpd 日志说:
[Sat Jun 20 04:42:02.970003 2020] [suexec:notice] [pid 1:tid 140041021270272] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.19.0.2. Set the 'ServerName' directive globally to suppress this message
[Sat Jun 20 04:42:02.994125 2020] [lbmethod_heartbeat:notice] [pid 1:tid 140041021270272] AH02282: No slotmem from mod_heartmonitor
[Sat Jun 20 04:42:02.995333 2020] [http2:warn] [pid 1:tid 140041021270272] AH02951: mod_ssl does not seem to be enabled
[Sat Jun 20 04:42:03.001899 2020] [mpm_event:notice] [pid 1:tid 140041021270272] AH00489: Apache/2.4.37 (centos) configured -- resuming normal operations
[Sat Jun 20 04:42:03.002120 2020] [core:notice] [pid 1:tid 140041021270272] AH00094: Command line: 'httpd -D FOREGROUND'
[Sat Jun 20 04:42:04.782201 2020] [proxy:error] [pid 8:tid 140040377865984] (2)No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /run/php-fpm/www.sock (*) failed
[Sat Jun 20 04:42:04.782280 2020] [proxy_fcgi:error] [pid 8:tid 140040377865984] [client 172.19.0.1:41072] AH01079: failed to make connection to backend: httpd-UDS
这个问题对我来说并不像看起来那么清楚。我认为这是一个 php-fpm 问题,但不知道如何解决它。查了一下,但所有解决方案似乎都很复杂。有没有一种简单的方法来告诉 PHP 与 Docker 镜像中的服务器一起工作?我最近阅读了有关使用像 supervisord 这样的流程管理器的文章,其中需要为每个容器启动多个服务。但是,是否可以在 Web 容器中以更简单的方式启动 PHP-FPM?
最佳答案
我在使用基本 rhel 8 图像时设法解决了这个问题
CMD ["bash", "-c", "/usr/sbin/apachectl start; /usr/sbin/php-fpm --nodaemonize"]
但是当我用base centos 8 image尝试它时,它不起作用,我不知道为什么
关于docker - 使用 Docker 创建基于 CentOS 8 的 PHP Web 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62481804/