Template for starting a containerized Django app with Postgres running on docker-compose, Also adding Gunicorn (a production-grade WSGI server), and Nginx (reverse proxy for Gunicorn to handle client requests as well as serve up static files) into the mix for production environments.
- Python 3.8.3
- Postgres 12.0
- Django 3.0.7
- gunicorn 20.0.4
- psycopg2-binary 2.8.5
- django-bootstrap4
docker-compose build
docker-compose up -d
docker-compose exec web python manage.py makemigrations
docker-compose exec web python manage.py migrate
Your App should be up and runnig on http://localhost:8000/ 😀
docker-compose exec web python manage.py createsuperuser
with this user you'll be able to login to the Django /admin page
docker-compose build
docker-compose up -d (-d for detached)
docker-compose down
docker-compose down -v (also removes the volumes along with the containers)
docker-compose logs -f -t (-f: follow the logs of all running services, -t: adds timestamps to logs)
docker-compose exec web python manage.py flush --no-input
docker-compose exec web python manage.py makemigrations
docker-compose exec web python manage.py migrate
docker-compose exec db psql --username=hello_django --dbname=hello_django_dev
docker-compose -f docker-compose.prod.yml down -v
docker-compose -f docker-compose.prod.yml up -d --build
docker-compose -f docker-compose.prod.yml exec web python manage.py migrate --noinput
docker-compose -f docker-compose.prod.yml exec web python manage.py collectstatic --no-input --clear
docker build -f ./app/Dockerfile -t hello_django:latest ./app
docker run -d \
-p 8006:8000 \
-e "SECRET_KEY=please_change_me" -e "DEBUG=1" -e "DJANGO_ALLOWED_HOSTS=*" \
hello_django python /usr/src/app/manage.py runserver 0.0.0.0:8000
This Template was created using this guide
Custom SystemUser was created using this guide
Bootstrap4 was added by following this guide
- Fork and Clone this repo
- Make a new branch
- Make necessary changes and commit those changes
- Push changes to GitHub
- Submit your changes for review (Pull Request)