Django app dev in Docker

django, docker, programming

Start with Docker’s doc

The link https://docs.docker.com/compose/django/ for the most part is valid in setting up a development environment for working with Django in Docker.

Update to use Pipfile

The document still uses the example of a requirements.txt to handle app dependencies. Django now has at least two newer alternatives:

  • Setup.py
  • Pipfile (pipenv)

One update to use pipenv is to modify the Dockerfile as such:

FROM python:3
ENV PYTHONUNBUFFERED 1

RUN mkdir /code
WORKDIR /code

COPY . /code/
RUN pip install pipenv && pipenv install
RUN pipenv run python manage.py migrate

That last command is optional; it can be deferred in the docker-compose.yml if that works better.

Speaking of docker-compose.yml:

version: '3'

services:
  web:
    build: .
    command: pipenv run python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"

(I removed the “db” service to keep this minimalistic.)