Skip to content

Django example #550

@williamhbell

Description

@williamhbell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions