Static Django files inside container

1. The problem I’m having:

I am running a Django website using gunicorn in a container. I installed Caddy on the (Ubuntu) host and made a reverse proxy to the container

This works for my website, and it looks nice, however I use django-bootstrap and I see it loads the css etc from a url. When I go to the Admin interface though, there is no styling and Firefox reports:

2. Error messages and/or full log output:

The resource from “http://e6b1.ts.net/static/admin/css/base.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://e6b1.ts.net/static/admin/js/nav_sidebar.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://e6b1.ts.net/static/admin/css/dark_mode.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http:/e6b1.ts.net/static/admin/css/nav_sidebar.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http:/e6b1.ts.net/static/admin/css/dashboard.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://e6b1.ts.net/static/admin/js/theme.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
Loading failed for the <script> with source “http://e6b1.ts.net/static/admin/js/theme.js”. admin:9:43
The resource from “http://e6b1.ts.net/static/admin/css/responsive.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://e6b1.ts.net/static/admin/css/nav_sidebar.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://e6b1.ts.net/static/admin/css/dashboard.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
admin
The resource from “http://e6b1.ts.net/static/admin/js/nav_sidebar.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

3. Caddy version:

v2.10.0 h1:fonubSaQKF1YANl8TXqGcn4IbIRUDdfAkpcsfI/vX5U=

4. How I installed and ran Caddy:

sudo apt install caddy

a. System environment:

Ubuntu 24.04
Django runs in a podman container with gunicorn

b. Command:

sudo systemctl start caddy

c. Service/unit/compose file:

services:
  rnaseqtracker:
    build:
      context: .
      dockerfile: Containerfile
    container_name: rnaseqtracker
    ports:
      - 127.0.0.1:8000:8000
    volumes:
      - ./db:/app/db

d. My complete Caddy config:

# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

:80 {
        # Set this path to your site's directory.
        #root * /usr/share/caddy

        # Enable the static file server.
        #file_server

        # Another common task is to set up a reverse proxy:
        reverse_proxy localhost:8000 

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000
}

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

This is a relevant section of my Django config:

STATIC_URL = 'static/'
STATIC_ROOT = Path(BASE_DIR, STATIC_URL)

I have tried several things on the caddy side, but nothing seems to work. I do find the static folder in the root of my website inside the container, but perhaps caddy does not know how to reach it?

5. Links to relevant resources:

You need to install mailcap inside the container

Just sudo apt -y install mailcap?

I’ll give it a shot and report back, as soon as users are not using the system…

… No change sadly, still have this admin interface:

Did you install it inside the container?

Yes I did.

Show your Containerfile

FROM docker.io/library/python:3.12-slim

LABEL authors="Moi"

WORKDIR /app

# Copy your Django application
COPY . /app

# Install dependencies
RUN pip install --no-cache-dir django==5.1.7 django-bootstrap5 django-tables2 django-model-utils django-taggit gunicorn pandas requests

# Copy the start script
COPY start.sh /start.sh

# Expose the port that Gunicorn will listen on
EXPOSE 8000

# Set the entrypoint to the start script
ENTRYPOINT ["/start.sh"]

Start.sh:

#!/bin/sh
cd /app
python manage.py migrate
python manage.py collectstatic --noinput
gunicorn rnaseqtracker.wsgi --bind 0.0.0.0:8000

I don’t see mailcap. Per Django docs:

To guess the served files’ content types, this view relies on the mimetypes module from the Python standard library, which itself relies on the underlying platform’s map files. If you find that this view doesn’t return proper content types for certain files, it is most likely that the platform’s map files are incorrect or need to be updated. This can be achieved, for example, by installing or updating the mailcap package on a Red Hat distribution, mime-support on a Debian distribution, or by editing the keys under HKEY_CLASSES_ROOT in the Windows registry.

1 Like