This is the Dockerfile for my Django project:
FROM python:3.10.5-alpine
ENV PYTHONDONTWRITEBYTECODEBYDEFAULT=1
ENV PYTHONUNBUFFERED=1
RUN adduser --disabled-password appuser
USER appuser
WORKDIR /home/appuser/app
COPY requirements.txt .
USER root
RUN python -m pip install --no-cache-dir --disable-pip-version-check --requirement requirements.txt
USER appuser
COPY . .
ENTRYPOINT [ "./entrypoint.sh" ]
And Django settings regarding static assets:
STATIC_URL = 'static/'
STATIC_ROOT = BASE_DIR / 'static/'
And entrypoint.sh
#!/bin/sh
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --no-input
gunicorn project.wsgi:application --bind=0.0.0.0:8000 --workers=4 --timeout=300 --log-level=debug --log-file=-
exec "$@"
When I start the container I shell into it and see that static
folder is created and populated with admin staff.
However browsing http://127.0.0.1:8000/admin
brings up the admin login page without any CSS and I get lots of 404
errors in the developer console.
I also changed STATIC_ROOT
to /home/appuser/app/static/
and got the same.
Please assist.
3
Answers
Did you check for the permissions of the created static folder?
I had to manually change the permissions of the folders.
you could try with following Dockerfile for nginx:
Could you try using this config.
Django:
Dockerfile:
Nginx.conf
docker-compouse.yml something like:
The static URL should start with
/
.You can also check the logs to see where it is trying to reach to.