Git Product home page Git Product logo

boardgames's Introduction

Dockerizing Django with Postgres, Gunicorn, and Nginx

Inspired from

This post. Related to this repo. Template boilerplate from repo.

The purpose is to build an hello world application to manage boardgames for Django discovery and exploratory exercise to determine best framework to use.

Django version selection

Before proceeding let s consider the Django version. Here I selected 3.1 which will be maintained until end of 2022.

3.2 next LTS will soon be available and should be migrated asap when done. ANother valid option should be using previous LTS 2.2 before switch to 3.2.

Consider djangoproject Supported versions before starting.

Model / db changes: Migrations

$ sudo docker-compose run web python manage.py makemigrations
$ sudo docker-compose run web python manage.py migrate

Development

Uses the default Django development server.

  1. Rename .env.dev-sample to .env.dev.

  2. Update the environment variables in the docker-compose.yml and .env.dev files.

  3. Build the images and run the containers:

    $ docker-compose up -d --build

    or

    $ sudo docker-compose up -d --build
  4. create a superuser (admin user)

  sudo docker-compose run web python manage.py createsuperuser
Test it out at [http://localhost:8000](http://localhost:8000). The "app" folder is mounted into the container and your code changes apply automatically.


Also test the Django admin funcionalities http://localhost:8000/admin](http://localhost:8000/admin).

App is published using the Django built in server capabilities. Not for production use, with the runserver option like this:

```sh
python manage.py runserver 0.0.0.0:8000
```

Troubleshooting

Start with looking at the logs like this :

$ docker-compose logs -f

or

$ sudo docker-compose logs -f

To restart use

$ docker-compose down -v

before rebuilding (to drop db and rebuild it if passwords database names changes).

Production

Uses gunicorn + nginx.

  1. Rename .env.prod-sample to .env.prod and .env.prod.db-sample to .env.prod.db. Update the environment variables.

  2. Build the images and run the containers:

    $ docker-compose -f docker-compose.prod.yml up -d --build

    or

    $ sudo docker-compose -f docker-compose.prod.yml up -d --build

    Test it out at http://localhost:1337. No mounted folders. To apply changes, the image must be re-built.

    App is published using nginx gunicorn webserver, may be used for production use.

    python manage.py runserver 0.0.0.0:8000

boardgames's People

Contributors

collaer avatar

Watchers

 avatar Jeremy Lykken 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.