【发布时间】:2015-02-23 01:25:03
【问题描述】:
我正在尝试使用来自 Docker 的 uWSGI 为 Django 应用程序提供服务。我正在使用 supervisord 在 Dockerfile 结束时为我启动该过程。当我运行图像时,它说 uWSGI 进程启动并成功,但我无法在我认为会显示它的 URL 上查看应用程序。也许我没有正确设置/配置东西?
我现在没有让 supervisord 启动 nginx,因为我目前正在通过 Amazon S3 提供静态文件,并且希望首先专注于启动和运行 wsgi。
我通过uwsgi --init uwsgi.ini:local 成功地在本地使用 uwsgi 运行了应用程序,但是我无法将其移动到 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
从一个使用 boot2docker 的 MAC,我试图访问 $(boot2docker ip):8080 的应用程序
最终我想将此容器上传到 AWS Elastic Beanstalk,不仅运行 uWSGI 进程,还运行 celery worker。
当我运行我的容器时,我可以从日志中看到 supervisor 和 uwsgi 都成功启动了。我能够单独使用 uwsgi 和通过主管使用 uwsgi 在我的本地机器上运行东西,但是由于某种原因,当我将东西容器化时,我在任何地方都找不到它。
这是我启动 docker 容器时记录的内容
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)
【问题讨论】:
标签: django docker uwsgi supervisord