Reusable Docker container to run a Django app with nginx and uwsgi
359
This is a reusable Docker container to run a Django app with nginx and uwsgi.
Features:
requirements.txt for Pythoncollectstatic and media foldersFROM inetss/django-app
# apt: libjpeg-dev libpq-dev
# python: python3.5
Django==1.9.5
psycopg2==2.6.1
...
#!/usr/bin/env python
import os
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings")
if __name__ == "__main__":
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
...
from .local_settings import *
Point MEDIA_ROOT here.
Point STATICFILES_ROOT here.
$ docker build -t app .
$ docker run -d --name app-postgres -e POSTGRES_PASSWORD=secret postgres
$ docker run --rm -it --name app --link app-postgres:postgres -e DJANGO_DEBUG=1 -v $(pwd)/var/media:/app/var/media -p 8000:80 app
Then open http://localhost:8000
The following environment variables are accepted:
DJANGO_DOCKER_SETTINGS=yIf set to "y", puts docker_settings.py helper near your settings.py
DJANGO_DOCKER_SETTINGS_FILE=docker_settings.pyOverrides docker_settings.py file name (see DJANGO_DOCKER_SETTINGS)
DJANGO_LOCAL_SETTINGS_FILE=docker_settings.pyCreates a symlink from that file to local_settings.py
The actual default is DJANGO_DOCKER_SETTINGS_FILE.
Ignored if DJANGO_DOCKER_SETTINGS is disabled.
DJANGO_LOCAL_SETTINGS_DEST_FILE=local_settings.pyCreates a symlink from docker_settings.py to this file.
Ignored if DJANGO_DOCKER_SETTINGS is disabled, or if the file already exists.
DJANGO_ADMIN_CREATE=yIf there is no users in the database, creates a default admin user. Supports custom User models.
DJANGO_ADMIN_USERNAME=adminDJANGO_ADMIN_PASSWORD=adminIf Docker settings integration is not disabled by DJANGO_DOCKER_SETTINGS=n, the following environment variables are additionally accepted:
DJANGO_ALLOWED_HOSTSComma-separated list that goes into Django ALLOWED_HOSTS.
DJANGO_DEBUGSet to anything non-empty to enable Django DEBUG.
MEMCACHED_PORT_11211_TCP_ADDR and friendsDiscovers a link to the official memcached Docker container and configures Django CACHES.
MEMCACHED_LOCATIONUse Django memcached location format (e.g. server:port).
MYSQL_PORT_3306_TCP_ADDR and friendsDiscovers a link to the official mysql Docker container and configures Django DATABASES.
MYSQL_HOSTMYSQL_PORTMYSQL_USER or MYSQL_USERNAMEDefaults to root.
MYSQL_PASS or MYSQL_PASSWORDMYSQL_DB or MYSQL_DATABASEPOSTGRES_PORT_5432_TCP_ADDR and friendsDiscovers a link to the official postgres Docker container and configures Django DATABASES.
POSTGRES_HOSTPOSTGRES_PORTPOSTGRES_USER or POSTGRES_USERNAMEDefaults to postgres.
POSTGRES_PASS or POSTGRES_PASSWORDPOSTGRES_DB or POSTGRES_DATABASESENTRY_DSNSet this to https://xxx:[email protected]/123 to enable Sentry reporting.
Place the config file at your Docker host (e.g. at /srv/app/config/local_settings.py):
from .settings import *
from .docker_settings import *
EMAIL_HOST = 'mail.company.org'
Then run Docker container with -v /srv/app/config/local_settings.py:/app/src/app/local_settings.py
Content type
Image
Digest
sha256:a04027c9c…
Size
233 MB
Last updated
over 1 year ago
docker pull inetss/django-app