Django example #718

Open
opened 2026-03-07 21:22:33 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @williamhbell on GitHub (Jan 29, 2025).

The https://github.com/docker/awesome-compose/blob/master/official-documentation-samples/django/README.md example instructions fail with

docker compose run web django-admin startproject composeexample .
...
  File "/usr/local/lib/python3.13/site-packages/django/core/management/commands/startproject.py", line 2, in <module>
    from django.core.management.templates import TemplateCommand
  File "/usr/local/lib/python3.13/site-packages/django/core/management/templates.py", line 1, in <module>
    import cgi
ModuleNotFoundError: No module named 'cgi'

The cgi module was removed from Python, such that django crashes when used with the latest official Python Docker image. The Dockerfile base image should be specified to avoid this issue. For example:

# syntax=docker/dockerfile:1
FROM python:3.11
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

works as expected.

Originally created by @williamhbell on GitHub (Jan 29, 2025). The https://github.com/docker/awesome-compose/blob/master/official-documentation-samples/django/README.md example instructions fail with ``` docker compose run web django-admin startproject composeexample . ... File "/usr/local/lib/python3.13/site-packages/django/core/management/commands/startproject.py", line 2, in <module> from django.core.management.templates import TemplateCommand File "/usr/local/lib/python3.13/site-packages/django/core/management/templates.py", line 1, in <module> import cgi ModuleNotFoundError: No module named 'cgi' ``` The `cgi` module was removed from Python, such that django crashes when used with the latest official Python Docker image. The Dockerfile base image should be specified to avoid this issue. For example: ``` # syntax=docker/dockerfile:1 FROM python:3.11 ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 WORKDIR /code COPY requirements.txt /code/ RUN pip install -r requirements.txt COPY . /code/ ``` works as expected.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/awesome-compose#718