Coder Social home page Coder Social logo

docker-django's Introduction

Django base image

hub.docker.com/r/telling/django

Based on the official python images.

Simplifying developing django applications by providing a few shorthands for manage.py:

  • runserver host:port
    • Waits for the database to be ready, then runs migrate, collectstatic and lastly runserver.
  • nomigrate host:port
    • Waits for the database to be ready, then runs collectstatic followed by runserver.
  • makemigrations and loadtestdata
    • Waits for the database to be ready, then runs makemigrations or loadtestdata.

If environment variables DJANGO_SUPERUSER_* are set, runserver and nomigrate will attempt to create the superuser. Likewise, if the DJANGO_DB_* variables are set, it will wait for the database upon starting the container, the image uses dockerize to wait for the database. Other then that it behaves like the official python images, with the environment variable PYTHONUNBUFFERED set, django and a few extra packages installed.

Environment variables

  • DJANGO_DB_HOST
  • DJANGO_DB_PORT
  • DJANGO_SUPERUSER_NAME
  • DJANGO_SUPERUSER_MAIL
  • DJANGO_SUPERUSER_PASS
  • PYTHONUNBUFFERED
  • DOCKERIZE_VERSION
  • DJANGO_VERSION

Usage

To start a new project and create a new app:

docker run --rm --log-driver none -v $(pwd):/code telling/django:1.9.7-py3 django-admin startproject mysite

docker run --rm --log-driver none -v $(pwd)/mysite:/code telling/django:1.9.7-py3 python manage.py startapp polls

docker-compose

I've recently used this to get a local development environment for the bornhack website.

I created a very simple dockerfile, which copies the requirements files and installs said requirements, Dockerfile:

FROM telling/django:1.9.7-py2

COPY requirements/base.txt base.txt
COPY requirements/development.txt development.txt
RUN pip install -r development.txt

CMD ["runserver", "0.0.0.0:8000"]

Then using the dockerfile in docker-compose.yml:

version: "2"

services:
  postgres:
    image: postgres:9.5
    container_name: bornhack-postgres
    environment:
      - POSTGRES_PASSWORD=bornhack
      - POSTGRES_USER=bornhack
      - POSTGRES_DB=bornhack_dev

  django:
    build: .
    volumes:
      - .:/code
    container_name: bornhack-django
    ports:
      - "8000:8000"
    environment:
      - DJANGO_DB_HOST=postgres
      - DJANGO_DB_PORT=5432
      - DJANGO_SUPERUSER_NAME=bornhack
      - DJANGO_SUPERUSER_PASS=bornhack
      - [email protected]
      - DJANGO_SETTINGS_MODULE=bornhack.settings.development

Change the settings file bornhack/settings/development.py and replace 'HOST': 'localhost', with 'HOST': 'postgres',. Now copy the environment file: cp bornhack/settings/env.dist bornhack/settings/.env

We end with a tree structure like:

.
├── Dockerfile
├── Makefile
├── README.md
├── bornhack
├── camps
├── docker-compose.yml
├── graphics
├── manage.py
├── news
├── profiles
├── requirements
├── shop
├── utils
├── vendor
└── villages

Then we can start hacking on the bornhack website by simply doing:

  • docker-compose up -d --build

Go to localhost:8000 and see the bornhack website in all its beauty.

docker-django's People

Contributors

telling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.