DEV Community

Django, Docker, and PostgreSQL Tutorial

Will Vincent on February 24, 2020

In this tutorial we will create a new Django project using Docker and PostgreSQL. Django ships with built-in SQLite support but even for local deve...
Collapse
 
rogerfc profile image
roger

Thanks for the tutorial, that's just what I needed atm.

I stepped into some problems, though. After switching to postgres you install psycopg2-binary locally but not in the container, right? but it's needed there to run, so I had to do it manually with docker-compose exec web pipenv install psycopg2-binary. Is this the right way?

In any case, when trying to run the migration I get this other error: django.db.utils.OperationalError: could not translate host name "db" to address: Name or service not known.

How can I fix this?

Collapse
 
sobolevn profile image
Nikita Sobolev

You can also try wemake-django-template: it has everything from this article in place. Docker for both development and production, docker-compose for better DX, django as the main framework, and postgres as the database.

Check it out:

GitHub logo wemake-services / wemake-django-template

Bleeding edge django template focused on code quality and security.

wemake-django-template

wemake.services Awesome Build Status Documentation Status Dependencies Status wemake-python-styleguide

Bleeding edge django2.2 template focused on code quality and security.


Purpose

This project is used to scaffold a django project structure Just like django-admin.py startproject but better.

Features

Installation

Firstly, you will need to install dependencies:

pip install cookiecutter jinja2-git

Then, create a project itself:

cookiecutter gh:wemake-services/wemake-django-template

Who are using this template?

If you use our template, please add yourself or your company in the list.

We offer free email support for anyone who is using this If you have any problems or questions,…