Public | Automated Build

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description

Django, NGINX, Gunicorn Container

This is a container for runing Django apps with Gunicorn and NGINX.

Usage

To use this container you must do the following:

  • create a Dockerfile that extends this container
  • ADD your app's WSGI file into your container at /container/conf/wsgi.py
  • place a requirements.txt file alongside your Dockerfile that specifies your Python dependencies

Your Dockerfile might look something like:

FROM shillaker/django-nginx
ADD my_app_conf/wsgi.py /container/conf/wsgi.py

Linking Your Database

It is assumed that you'll be running a separate container for your database. For example, you may be running the
postgres image like this:

sudo docker run -d --name database \
            -e POSTGRES_USER="docker_demo" \
            -e POSTGRES_PASSWORD="db_pass" \
            postgres

To link this into your Django container you would then need to modify your DATABASES setting to:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'docker_demo',
        'USER': 'docker_demo',
        'PASSWORD': 'db_pass',
        'HOST': 'database',
        'PORT': '5432',
    }
}

See the postgres repo for details on how to configure the postgres image.

Static/ Media Directories

A couple of directories are created ready to use for static and media files at /web/static and
/web/media respectively. These should be reflected in your
Django settings.py (or overridden with your own):

STATIC_ROOT = '/web/static/'
MEDIA_ROOT = '/web/media/'

Running the Container

Once you have set up your project as described above, you will need to build and run it and link in a database.

For example:

sudo docker build -t my_user/django-nginx .

sudo docker run -i -t -d \
    -p 80:80 \
    --link database:database \
    my_user/django-nginx

Environment Variables

You may also find it useful to set your DJANGO_SETTINGS_MODULE environment variable in your Dockerfile e.g.

ENV DJANGO_SETTINGS_MODULE my_app_conf.settings

Example

An example Django project using this image can be found here.

Adding Your Own Start Script

This container will run is own start script using the CMD directive in the Dockerfile. If you want to extend
the start script to perform your own initialisation you must copy a script over to /container/scripts/start.sh.

For example, if your script was at my_scripts/my_start_script.sh in your project, you would add this line to your
Dockerfile:

ADD my_scripts/my_start_script.sh /container/scripts/start.sh

Overriding Config

The container provides vanilla Gunicorn and NGINX configs, however, if you want to override them you can do so by
ADDing them into /container/conf/gunicorn_app.conf and /container/conf/nginx_app respectively.

Docker Pull Command
Owner
shillaker
Source Repository

Comments (0)