Hot Reloading in Docker Container not working Django

I'm having problems with my VS-Code Dev Container. It is running, but unfortunately, the StatReloader does not work. If I run uv run python manage.py runserver 0.0.0.0:6000 inside the Dev Container (an start a new Django server) it is working perfectly fine. Actually, I'm not sure if the problem is related to Dev Containers because the StatReloader does not work in the Docker container in general.

I've tried to...

  • change the volume in .devcontainer/docker-compose.yml to .:/workspace:delegated
  • change the workspaceFolder to workspace
  • run Django with gunicorn
# backend/Dockerfile
FROM python:3.12
EXPOSE 8000
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
RUN apt-get update && apt-get install -y inotify-tools
RUN pip install uv watchdog
WORKDIR /app
COPY pyproject.toml uv.lock ./
COPY . ./
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
RUN uv sync && uv lock
CMD [ "uv", "run", "python", "manage.py", "runserver", "0.0.0.0:8000" ]
# docker-compose.yml
name: experiments-graphql
services:
  django:
    image: backend
    build:
      context: ./backend
      dockerfile: ./Dockerfile
    ports:
      - 8000:8000
    restart: "unless-stopped"
# .devcontainer/docker-compose.yml
services:
  django:
    volumes:
      - .:/workspace:rw,consistent
// .devcontainer.json/devcontainer.json
{
    "name": "Existing Docker Compose (Extend)",

    "dockerComposeFile": [
        "../docker-compose.yml",
        "docker-compose.yml"
    ],

    "service": "django",
    "workspaceFolder": "/workspace",

    "customizations": {
        "vscode": {
            "settings": {},
            "extensions": [
                "ms-python.python",
                "eamodio.gitlens",
                "editorconfig.editorconfig"
            ]
        }
    }
}
Back to Top