Code Monkey home page Code Monkey logo

django-simple-asgi's Introduction

Docker setup for Django Polls app + Postgres + Uvicorn + Gunicorn + Nginx


This is a Django stack on Docker with focus on simplicity. The Django application sitting in the djangoapp directory is based on the official Polls tutorial. Since it is mounted into the container, code changes will be automatically applied. All the customizable configuration variables are in the config directory.

Quick Start

If you are in a hurry, just follow these steps:

cp config/django/example.env config/django/.env
cp config/postgres/example.env config/postgres/.env
docker-compose up -d --build
docker-compose run djangoapp python manage.py migrate
docker-compose run djangoapp python manage.py collectstatic --no-input -v 2

Wait for a few seconds for the services to be up and running. Then open the app at http://localhost

Common Tasks

Shutting Down

docker-compose down

Load Initial Data

docker-compose run djangoapp /bin/sh -c "python manage.py flush; python manage.py migrate; python manage.py loaddata potter-fixture.json"
docker-compose run djangoapp python manage.py createsuperuser

View Error Logs

If running in the project directory django-wsgi-simple then it is usually:

docker logs django-wsgi-simple_nginx_1
docker logs django-wsgi-simple_djangoapp_1

Cleanup

Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.

docker system prune -f
docker system prune -f --volumes

Production

In production, you might have to make many changes especially around security. It is recommended to create an application user as Docker containers will use the root user by default. The permissions can be restricted to that user. The docker image sizes can be reduced with multi-stage builds.

Refer code from testdriven.io, rowdybeaver and Docker official docs for details on the docker-compose production setup.

Note: typically you would use a cloud-based database than run a database like Postgres in a docker container (why? but some people have no issues) in production. Even more, if you have a popular app then you will need something like Docker Swarm or Kubernetes rather than Docker Compose to scale up.

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.