django - uWSGI与Docker的Supervisord一起提供的应用程序

标签 django docker uwsgi supervisord

我正在尝试使用来自Docker的uWSGI提供Django应用程序。我正在使用supervisor在Dockerfile的末尾为我启动该过程。当我运行该镜像时,它表示uWSGI进程已启动并成功,但是我无法以我认为会显示它的URL来查看该应用程序。也许我没有正确设置/配置东西?

我现在没有监督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。

运行容器时,从日志中可以看到主管和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)

最佳答案

您如何启动Docker容器?

我看不到任何CMD或ENTRYPOINT脚本,因此不清楚如何开始。

通常,除非绝对必要,否则我建议避免使用supervisor之类的方法,只需从CMD行在前台启动uWSGI。尝试将以下内容添加到Dockerfile的最后一行:

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

然后使用docker run -p 8000:8000 image_name运行。您应该从uWSGI得到一些答复。如果可行,我建议您将其他服务(postgres,node,移至单独的容器)。有Node,Python和Postgres的官方图片,可以为您节省一些时间。

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

关于django - uWSGI与Docker的Supervisord一起提供的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27645156/

相关文章:

bash - docker 日志和缓冲输出

django - uWSGI不会重新加载、重新启动或让我运行服务

django - 使用 Django 同时运行 UWSGI 和 ASGI

java - Java 的 Django 管理风格应用程序

python - 强制重置手动创建的用户密码

django - ManyToManyField 和南迁移

docker - 如何在容器运行时在 docker-compose.yml 中替换服务命令中的环境变量?

python - Django 表单无法识别模型属性

python - 无法连接到 Docker 中的 MySql。抛出拒绝访问错误。 Flask-SqlAlchemy

python - 如何在由 uswgi 提供服务并由 systemd 服务启动的虚拟环境中配置 Django 应用程序?