django - 在 Docker 上使用 Nginx、uWSGI 和 Postgres 配置 Django

标签 django postgresql nginx docker docker-compose

我正在尝试使用 Nginx、uWSGI 和 Postgres 在 Docker 上设置 Django 应用程序。我找到了关于为 Django 和 Postgres 设置 Compose 的精彩指南:https://docs.docker.com/v1.5/compose/django/

但是,现在我需要添加 Nginx 和 uWSGI。遗憾的是,我已尝试将此 repo ( https://github.com/baxeico/django-uwsgi-nginx) 的文件与 Docker 文档的 Compose 设置一起使用,但没有成功。

这是当我输入 docker-compose run web 时发生的情况:

Step 17 : RUN pip install -r /home/docker/code/app/requirements.txt
 ---> Running in e1ec89e80d9c
Collecting Django==1.9.1 (from -r /home/docker/code/app/requirements.txt (line 1))
/usr/local/lib/python2.7/dist-packages/pip-7.1.2-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading Django-1.9.1-py2.py3-none-any.whl (6.6MB)
Collecting psycopg2 (from -r /home/docker/code/app/requirements.txt (line 2))
  Downloading psycopg2-2.6.1.tar.gz (371kB)
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    Error: pg_config executable not found.

    Please add the directory containing pg_config to the PATH
    or specify the full executable path with the option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-XRgbSA/psycopg2
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r /home/docker/code/app/requirements.txt' returned a non-zero code: 1

这是我的 Dockerfile:

from ubuntu:precise

run echo "deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted" | tee -a /etc/apt/sources.list.d/precise-updates.list

# update packages
run apt-get update

# install required packages
run apt-get install -y python python-dev python-setuptools python-software-properties
run apt-get install -y sqlite3
run apt-get install -y supervisor

# add nginx stable ppa
run add-apt-repository -y ppa:nginx/stable
# update packages after adding nginx repository
run apt-get update
# install latest stable nginx
run apt-get install -y nginx

# install pip
run easy_install pip

# install uwsgi now because it takes a little while
run pip install uwsgi

# install our code
add . /home/docker/code/

# setup all the configfiles
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
run pip install -r /home/docker/code/app/requirements.txt

run cd /home/docker/code/app && ./manage.py syncdb --noinput

expose 80
cmd ["supervisord", "-n"]

还有 docker-compose.yml:

db:
  image: postgres
web:
  build: .
  command: python vms/manage.py runserver 0.0.0.0:8000
  volumes:
    - .:/code
  ports:
    - "8000:8000"
  links:
    - db

还有名为 nginx-app.conf、supervisor-app.conf、uwsgi_params 和 uwsgi.ini 的文件。这些都来自上述 repo 协议(protocol)。 Requirements.txt 包含 Django 1.9.1、psycopg2 和请求。

如果这个科学怪人项目有更好的替代方案,我很想听听。

最佳答案

在 Ubuntu 上,确保 python-devlibpq-dev 已经使用 apt-get 安装,然后再尝试安装 psycopg2 使用 pip。

参见 installation docs了解更多信息。

关于django - 在 Docker 上使用 Nginx、uWSGI 和 Postgres 配置 Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34657620/

相关文章:

SQL 按日期范围分组

nginx - docker-compose + nginx-proxy + Letsencrypt-nginx-proxy-companion + gitlab-ce = git 克隆上的 SSH 连接失败

python - django 身份验证 URL 的默认命名空间是什么?

python - 如何将javascript添加到change_form.html中以获取django中的 block 内容

python - 似乎无法丢失此错误 : "You are trying to add a non-nullable field"

javascript - 为什么在 Nginx 中增加 worker_connections 会使应用程序在 node.js 集群中变慢?

node.js - 502 Bad Gateway 在 Elastic Beanstalk 上部署 Express Generator 模板

django - 如何在 Django 中上传之前预览图像

postgresql - 在一组多边形中查找 GPS 点

node.js - Sequelize - 如果与另一个模型存在关系,我如何 "select"模型的实例