Public | Automated Build

Last pushed: a year ago
Short Description
Base container to deploy Django applications with Python 3, nginx proxy and gunicorn
Full Description

Django, NGINX, Gunicorn and Supervisord 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
  • place a requirements.txt file alongside your Dockerfile that specifies your Python dependencies

Your Dockerfile might look something like:

FROM medhra/docker_django_nginx

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 PG_USER="docker_demo" \
            -e PG_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'
    }
}

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 /home/app/static and
/home/app/media respectively. These should be reflected in your
Django settings.py (or overridden with your own):

STATIC_ROOT = '/home/app/static/'
MEDIA_ROOT = '/home/app/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
Docker Pull Command
Owner
medhra
Source Repository