Public | Automated Build

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

Djangunix

Django + Gunicorn + Nginx in a docker container

Setup

Build base image:

$ docker build --rm -t djangunix .

or pull it from the docker hub:

$ docker pull tailordev/djangunix

Then use it in your django app:

# Dockerfile

FROM tailordev/djangunix

ENV PROJECT_NAME {{ project_name }}

project_name is the directory of your django app containing your settings, urls and wsgi files:

project_name
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py

Usage

Configuration volumes

Each configuration file may be overridden thanks to the following docker volumes:

  • nginx: /etc/nginx/sites-available/[django]
  • supervisor: /etc/supervisor/conf.d/[django.conf]
  • gunicorn: /usr/local/etc/gunicorn/[django.py]

Build and run your container

$ cd your/project_name
$ docker build --rm -t project_name .
$ docker run -p 80:80 -v $PWD:/home/django/app project_name

And voilà. Your app is up!

Run django-admin commands

Run collectstatic in a running container:

$ docker exec $(docker ps --filter=[name=project_name] -q) python manage.py collectstatic --noinput

Link your container to a PostgreSQL container using docker-compose

Create a docker-compose.yml file at the root of your project containing:

django:
  build: .
  volumes:
    - .:/home/django/app
  ports:
    - "80:80"
  links:
    - db

db:
  image: postgres:9

And then start your stack with a single command:

$ docker-compose up

This will build, run and link your djangunix container with a postgres image container.

Docker Pull Command
Owner
tailordev
Source Repository

Comments (0)