uWSGI通过Docker的Supervisord服务应用程序

我正尝试从Docker中为uWSGI提供一个Django应用程序。 我使用supervisord在Dockerfile的结尾处为我启动进程。 当我运行图像时,它说uWSGI进程启动并成功,但我无法在我认为会显示的URL上查看该应用程序。 也许我没有正确的设置/configuration的东西?

我现在没有supervisord启动nginx,因为我目前正在通过Amazon S3提供静态文件,并且希望首先关注如何让wsgi启动并运行。

我成功地使用uwsgi在本地运行uwsgi --init uwsgi.ini:local来运行应用程序,但我无法将它移到docker中。

这是我的Dockerfile

 FROM ubuntu:14.04 # Get most recent apt-get RUN apt-get -y update # Install python and other tools RUN apt-get install -y tar git curl nano wget dialog net-tools build-essential RUN apt-get install -y python3 python3-dev python-distribute RUN apt-get install -y nginx supervisor # Get Python3 version of pip RUN apt-get -y install python3-setuptools RUN easy_install3 pip RUN pip install uwsgi RUN apt-get install -y python-software-properties # Install GEOS RUN apt-get -y install binutils libproj-dev gdal-bin # Install node.js RUN apt-get install -y nodejs npm # Install postgresql dependencies RUN apt-get update && \ apt-get install -y postgresql libpq-dev && \ rm -rf /var/lib/apt/lists ADD . /home/docker/code # Setup config files RUN echo "daemon off;" >> /etc/nginx/nginx.conf RUN rm /etc/nginx/sites-enabled/default RUN ln -s /home/docker/code/nginx-app.conf /etc/nginx/sites-enabled/ RUN ln -s /home/docker/code/supervisor-app.conf /etc/supervisor/conf.d/ RUN pip install -r /home/docker/code/app/requirements.txt EXPOSE 8080 CMD ["supervisord", "-c", "/home/docker/code/supervisor-app.conf", "-n"] 

这是我的uwsgi.ini

 [uwsgi] # this config will be loaded if nothing specific is specified # load base config from below ini = :base # %d is the dir this configuration file is in socket = %dmy_app.sock master = true processes = 4 [dev] ini = :base # socket (uwsgi) is not the same as http, nor http-socket socket = :8001 [local] ini = :base http = :8000 # set the virtual env to use home=/Users/my_user/.virtualenvs/my_env [base] # chdir to the folder of this config file, plus app/website chdir = %dmy_app/ # load the module from wsgi.py, it is a python path from # the directory above. module=my_app.wsgi:application # allow anyone to connect to the socket. This is very permissive chmod-socket=666 http = :8080 

这里是我的supervisor-app.conf文件

 [program:app-uwsgi] command = /usr/local/bin/uwsgi --ini /home/docker/code/uwsgi.ini 

从MAC使用boot2docker,我试图访问$(boot2docker IP)的应用程序:8080

最终,我想将此容器上传到AWS Elastic Beanstalk,不仅运行uWSGI进程,而且还运行芹菜工作器。

当我运行我的容器时,我可以从日志中看到,supervisor和uwsgi都成功启动。 我能够通过uwsgi本身和uwsgi通过pipe理员在本地机器上运行,但是由于某种原因,当我容器找不到任何地方的东西的时候。

以下是我启动Docker容器时logging的内容

 2014-12-25 15:08:03,950 CRIT Supervisor running as root (no user in config file) 2014-12-25 15:08:03,953 INFO supervisord started with pid 1 2014-12-25 15:08:04,957 INFO spawned: 'uwsgi' with pid 9 2014-12-25 15:08:05,970 INFO success: uwsgi entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 

你如何启动docker集装箱?

我没有看到任何CMD或ENTRYPOINT脚本,所以我不清楚如何开始。

一般来说,我build议避免像supervisord这样的事情,除非绝对必要,只需从CMD行的前台启动uWSGI即可。 尝试添加以下内容作为Dockerfile中的最后一行:

 CMD ["/usr/local/bin/uwsgi", "--ini", "/home/docker/code/uwsgi.ini"] 

然后运行docker run -p 8000:8000 image_name 。 你应该从uWSGI得到一些回复。 如果这样做,我build议你移动其他服务(postgres,节点,分开容器)。 有Node,Python和Postgres的官方图像,这应该为您节省一些时间。

请记住,Docker容器只能在其主进程(必须在前台)上运行。