在Docker上配置Django、Nginx、uWSGI和Postgres

4
我正在尝试使用Docker、Nginx、uWSGI和Postgres来设置Django应用程序。我在设置Compose时找到了这个非常棒的指南,可以帮助我设置Django和Postgres:https://docs.docker.com/v1.5/compose/django/ 然而,现在我需要添加Nginx和uWSGI。我尝试使用此存储库的文件(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的文件。这些都来自上述仓库。requirements.txt包含Django 1.9.1、psycopg2和requests。

如果有更好的替代方案,我很乐意听取建议。

1个回答

4
在Ubuntu上,安装psycopg2之前,请确保使用apt-get安装了python-devlibpq-dev。请参阅安装文档以获取更多信息。

我忘记了libpq-dev,将其添加到我的dockerfile中解决了问题。非常感谢! - Pharetra

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接