
# For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 'ĪLLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ") # 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a space between each. Update the SECRET_KEY, DEBUG, and ALLOWED_HOSTS variables in settings.py: SECRET_KEY = os.environ.get("SECRET_KEY")ĭEBUG = int(os.environ.get("DEBUG", default=0)) Review the Compose file reference for info on how this file works. Next, add a docker-compose.yml file to the project root: version: '3.7'Ĭommand: python manage.py runserver 0.0.0.0:8000 Review Docker for Python Developers for more on structuring Dockerfiles as well as some best practices for configuring Docker for Python-based development.
POSTGRES INSTALL FOR DJANGO MAC OSX INSTALL
# install dependencies RUN pip install -upgrade pip # set environment variables ENV PYTHONDONTWRITEBYTECODE 1 # set work directory WORKDIR /usr/src/app Install Docker, if you don’t already have it, then add a Dockerfile to the “app” directory: # pull official base image FROM python:3.8.3-alpine Your project directory should look like: └── app Since we’ll be moving to Postgres, go ahead and remove the db.sqlite3 file from the “app” directory. We now have a simple Django project to work with.Ĭreate a requirements.txt file in the “app” directory and add Django as a dependency: Django=3.0.7 Kill the server and exit from the virtual environment once done.

Navigate to view the Django welcome screen. įeel free to swap out virtualenv and Pip for Poetry or Pipenv. (env)$ django-admin.py startproject hello_django.

Dockerizing Django with Postgres, Gunicorn, and Nginx (this article!).
POSTGRES INSTALL FOR DJANGO MAC OSX HOW TO
We’ll also take a look at how to serve Django static and media files via Nginx. For production environments, we’ll add on Nginx and Gunicorn. This is a step-by-step tutorial that details how to configure Django to run on Docker with Postgres.
