这是我的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
这是我的要求.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
这个事实,但它在码头工人身上没有任何地方"文件系统"所以我必须使用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
答案 0 :(得分:2)
从你的所有输出中,你的httpd / uwsgi进程肯定绑定到8000,这是你需要在容器上公开的端口。
netstat中的这一行显示8000的绑定,没有别的。
tcp 0 0 *:irdmi *:* LISTEN
这里并不明显,但如果您使用--numeric-ports
参数,则不会将8000转换为known port。
在您的泊坞窗文件中,您应该再次
EXPOSE 8000
启动容器时,您还可以指定要在主机上使用的端口:
docker run -p 8080:8000 --name ...
在此之后,您应该可以使用浏览器点击
localhost:8080 -> container:8000
答案 1 :(得分:1)
将此添加到您的Dockerfile中,就在CMD之前:
WORKDIR /usr/src/app/
假设您的start-apache-server文件位于该目录中。这将有助于wsgi找到所需的文件。