ERR_EMPTY_RESPONSE for localhost when running Docker



这是我的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

这是我的要求:

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" Filesystem"上没有任何地方,因此我必须使用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进程肯定绑定到8000,这是您需要在容器上公开的端口。

NetStat中的这一行,正在显示8000的绑定,没有其他。

tcp        0      0 *:irdmi                     *:*                         LISTEN      

这里并不明显,但是如果您使用--numeric-ports参数,它不会将8000转换为已知端口。

在您的Docker文件中,您应该再次

EXPOSE 8000

启动容器时,您还可以指定主机上使用的端口:

docker run -p 8080:8000 --name ...

之后,您应该能够使用浏览器击中

localhost:8080  ->  container:8000

在CMD之前,将其添加到您的Dockerfile:

之前
WORKDIR  /usr/src/app/

假设您的start-apache-server文件在该目录中。这将帮助WSGI找到所需的文件。

最新更新