我正在尝试使用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进程,还运行芹菜工作者。
当我运行我的容器时,我可以从日志中看到主管和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)
答案 0 :(得分:3)
你是如何启动docker容器的?
我没有看到任何CMD或ENTRYPOINT脚本,因此我不清楚如何开始。
一般来说,除非绝对必要,否则我会建议避免像supervisord这样的事情,只需从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容器只运行其主进程(必须位于前台)。