繁体   English   中英

使用 CMD 启动 Docker PHP 服务器使主机在连接时收到“由对等方重置的连接”

[英]Starting Docker PHP server using CMD makes the host recieve "Connection reset by peer" upon connecting

我有一个 PHP 服务器,我需要沿着 Python 服务在 docker 映像中启动它。 它们都需要在同一个图像中。 起初,我按照我在网上找到的一个简单指南编写了 Dockerfile 来启动 PHP 服务器,我想出了这个:

FROM php:7-apache
COPY ./www/ /var/www/html
WORKDIR /var/www/html
EXPOSE 70

然后,因为我需要在第二个容器上运行第三个服务,所以我创建了以下 docker-compose 文件:

version: '3.3'

services:
  web:
    build: .
    image: my-web
    ports:
      - "70:80"
  secondary-service:
    image: my-service
    ports:
      - "8888:8888"

仅使用它,网站就可以正常工作( web容器上缺少的服务除外)。 但是,如果我想在web容器中与 web 一起启动服务,我需要从 bash 脚本手动启动网站,因为 docker 只能有一个 CMD 条目。 这是我尝试过的:

FROM php:7-apache
COPY ./www/ /var/www/html
RUN mkdir "/other_service"
COPY ./other_service /other_service
RUN apt-get update && bash /other_service/install_dependenci172.17.0.1es.sh
WORKDIR /var/www/html
EXPOSE 70
CMD ["bash", "/var/www/html/launch.sh"]

这是launch.sh

#!/bin/bash

(cd /other_service && python3 /other_service/start.py &) # CWD needs to be /other_service/
php -S 0.0.0.0:70 -t /var/www/html

这也可以毫无问题地启动服务器,以及other_service 但是,当我转到我的浏览器(在主机中)并浏览到http://localhost:70时,我收到错误“连接重置”。 当我尝试使用curl localhost:70发出请求时也会发生同样的情况,这会导致curl: (56) Recv failure: Connection reset by peer

我可以在web的日志中看到 php 测试服务器正在运行:

PHP 7.4.30 Development Server (http://0.0.0.0:70) started

如果我在容器内打开一个外壳并在其中运行curl命令,它会毫无问题地获取网页。

我一直在搜索类似的问题,但如果他们有答案,那就没有了,而那些没有用的。

到底是怎么回事? 不应该从 bash 脚本手动启动服务器就可以了?

编辑:我刚刚尝试只启动 PHP 服务器,如下所示,它也不让我连接到网页

#!/bin/bash

#(cd /other_service && python3 /other_service/start.py &) # CWD needs to be /other_service/
php -S 0.0.0.0:70 -t /var/www/html

我发现了这个问题。 就像启动 Apache 服务器一样简单:

#!/bin/bash

(cd /other_service && python3 /other_service/start.py &) # CWD needs to be /other_service/
/etc/init.d/apache2 start
php -S 0.0.0.0:70 -t /var/www/html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM