gpt4 book ai didi

apache - 运行 Docker 时本地主机的 ERR_EMPTY_RESPONSE

转载 作者:行者123 更新时间:2023-12-02 18:15:50 24 4
gpt4 key购买 nike

这是我的 Dockerfile:

# CentOs base image
FROM centos:centos6.8

# install python, pip, apache and other packages
RUN yum -y update; yum clean all
RUN yum -y install epel-release; yum clean all
RUN yum -y install centos-release-scl; yum clean all
RUN yum -y install python27; yum clean all
RUN yum -y install python-devel.x86_64; yum clean all
RUN yum -y install python-pip; yum clean all
RUN yum -y install gcc; yum clean all
RUN yum -y install httpd httpd-devel mod_ssl; yum clean all

# Make a non root user so I can run mod_wsgi without root
# USER adm

# install Python modules needed by the Python app
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt

# copy files required for the app to run
COPY . /usr/src/app/

# tell the port number the container should expose
EXPOSE 80

# run the application
# CMD ["mod_wsgi", "start-server run_apache_server.wsgi"]
# CMD ["cat", "/etc/passwd"]
# CMD ["cat", "/etc/group"]
# CMD ["find", "/"]
CMD ["/bin/sh", "-c", "/usr/bin/mod_wsgi-express start-server run_apache_server.wsgi --user adm --group apache"]

我可以运行应用程序:
$ docker run -d -P --name myapp jacobirr/pleromatest

并查看 tcp 端口 80:
$ docker port myapp
80/tcp -> 0.0.0.0:32769

这是我的requirements.txt:
Flask==0.10.1
Flask-Restless==0.13.1
Flask-SQLAlchemy==0.16
Jinja2==2.7
MarkupSafe==0.18
SQLAlchemy==0.8.2
Werkzeug==0.9.2
gunicorn==17.5
itsdangerous==0.22
mimerender==0.5.4
python-dateutil==2.1
python-mimeparse==0.1.4
requests==1.2.3
six==1.3.0
wsgiref==0.1.2
setuptools==5.4.2
mod_wsgi==4.5.15

为什么我无法访问 localhost:32769在浏览器中?我怀疑这与:

• 运行apache 的用户/组?

•事实上我正在安装 mod_wsgi但它在 docker“文件系统”上没有,所以我必须使用 mod_wsgi-express ?

更新:

'1' Netstat 显示:
[root@9003b0d64916 app]# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:irdmi *:* LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 113181 /tmp/mod_wsgi-localhost:8000:0/wsgi.1.0.1.sock

'2' httpd 似乎正在我的容器中运行:
[root@9003b0d64916 mod_wsgi-localhost:8000:0]# ps aux | grep httpd
root 1 0.0 0.2 64060 5084 ? Ss 21:17 0:00 httpd (mod_wsgi-express) -f /tmp/mod_wsgi-localhost:8000:0/httpd.conf -k start -DFOREGROUND
adm 6 0.0 0.6 350928 13936 ? Sl 21:17 0:00 (wsgi:localhost:8000:0) -f /tmp/mod_wsgi-localhost:8000:0/httpd.conf -k start -DFOREGROUND
adm 7 0.0 0.1 64192 3248 ? S 21:17 0:00 httpd (mod_wsgi-express) -f /tmp/mod_wsgi-localhost:8000:0/httpd.conf -k start -DFOREGROUND

最佳答案

从您的所有输出中,您的 httpd/uwsgi 进程肯定绑定(bind)到 8000,这是您需要在容器上公开的端口。

netstat 中的这一行显示 8000 上的绑定(bind),仅此而已。

tcp        0      0 *:irdmi                     *:*                         LISTEN      

这里并不明显,但如果你使用 --numeric-ports参数,它不会将 8000 转换为其 known port .

在您的 docker 文件中,您应该再次
EXPOSE 8000

启动容器时,您还可以指定要在主机上使用的端口:
docker run -p 8080:8000 --name ...

在此之后,您应该可以使用浏览器点击
localhost:8080  ->  container:8000

关于apache - 运行 Docker 时本地主机的 ERR_EMPTY_RESPONSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44400048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com