Nginx can not find static files in my docker instance

Hi I have a Django application that I'm preparing for deployment on a local network using docker. My Nginx proxy is unable to find the static files

here is my docker-compose-deploy.yaml file:

services:
  app:
    build:
      context: .
    volumes:
      - ./inventory/static:/vol/web/static
      - ./qr_codes:/vol/web/qr_codes
  
  proxy:
    build:
      context: ./nginx
    volumes:
      - static:/app/static/
    ports:
      - "8080:8080"
    depends_on:
      - app

  db:
    image: postgres
    restart: always
    volumes:
      - ./data/db:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: Inventory
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: 123456

  pgadmin:
    image: dpage/pgadmin4
    restart: always
    ports:
      - "5050:5050"
    environment:
      PGADMIN_DEFAULT_EMAIL: jacob@me.com
      PGADMIN_DEFAULT_PASSWORD: 123456
      PGADMIN_LISTEN_ADDRESS: 0.0.0.0
      PGADMIN_LISTEN_PORT: 5050

volumes:
  static:
  postgres_data:

here is my DockerFile for my Django app:

# Use the official Python image from the Docker Hub
FROM python:3.8-alpine

# Set environment variables
ENV PATH="/scripts:${PATH}"

# Install dependencies
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
RUN pip install --no-cache-dir -r /requirements.txt
RUN apk del .tmp

# Create and set permissions for directories
RUN mkdir -p /app/vol/web/static /app/vol/web/qr_codes
RUN adduser -D user
RUN chown -R user:user /app/vol
RUN chmod -R 755 /app/vol

# Copy project files
COPY ./ /app
WORKDIR /app
COPY ./scripts /scripts
RUN chmod +x /scripts/*

# Set the user to 'user'
USER user

# Command to run the application
CMD ["entrypoint.sh"]

My Docker file for Nginx proxy:

FROM nginxinc/nginx-unprivileged:1.19-alpine

COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./uwsgi_params /etc/nginx/uwsgi_params

USER root
RUN mkdir -p /vol/static 
RUN chmod -R 755 /vol/static

USER nginx

My default.conf file for Nginx:

server{
    listen 8080;

    location /static {
        alias /static/;
    }

    location /{
        uwsgi_pass app:8000;
        include /etc/nginx/uwsgi_params;
    }
}

In my settings.py file

STATIC_URL = '/static/'
MEDIA_URL = '/static/qr_codes/'

STATIC_ROOT = 'vol/web/static'
STATIC_MEDIA = 'vol/web/qr_codes'

I get this error in my docker terminal:

proxy-1    | 172.18.0.1 - - [13/Nov/2024:14:37:45 +0000] "GET /static/static/vendor/jsqr/dist/jsQR.js HTTP/1.1" 404 556 "http://127.0.0.1:8080/inventory/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" "-"
Вернуться на верх