The thing is that i have set up dockerfiles, docker-compose is running everything as it should be. Databases is connected and all the staff. But the only problem is, that i cant load staticfiles. Gunicorn informs, that files "Not Found" both admin, and rest_framework static files. Even though it creates 'static' in the root directory, but doesn't collect static there, while dockerfile run.
When im doing "docker-compose up" it says that `0 static files were copied to '/static', 165 unmodified
So far i have checked paths which are configured in STATIC_ROOT and STATIC URL. Also, modified my docker-compose file:
version: '3.11'
services:
django_gunicorn:
volumes:
- static:/static/
env_file:
- .env
build:
context: .
ports:
- "8000:8000"
nginx:
build: ./nginx
volumes:
- ./backend/service/static:/backend/static
ports:
- "80:80"
depends_on:
- django_gunicorn
- db
db:
image: postgres
expose:
- 5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
volumes:
static:
Also i have inspected nginx config file one more time:
upstream django {
server django_gunicorn:8000;
}
server {
listen 80;
location / {
proxy_pass http://django;
}
location /static/ {
autoindex on;
alias /static/;
}
}
i have also tried different approaches to setting up root and url of staticfiles, but left it like this for now:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
Also there were suggestions to run "collectstatic" first, which i have already done, but no effect, so ive deleted static folder for now, because i didnt see 'static' folder in other applications as well.
entrypoint/sh
#!/bin/sh
python manage.py migrate --no-input
python manage.py collectstatic --no-input
gunicorn config.wsgi:application --bind 0.0.0.0:8000
Here is my Dockerfile:
FROM python:3.11
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt \
python manage.py collectstatic \
pip install python-dotenv
COPY ./backend /app
WORKDIR /app
COPY ./entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]