Модуль не найден в uwsgi.ini при настройке Django и Docker
У меня возникает странная ошибка при попытке запустить сервер Django в Docker с uWSGI, по какой-то причине конфигурационный файл не может определить путь к файлу wSGI Django.
Я запустил приложение с обычным "runserver" и все работает нормально, так что проблема не в приложении Django, а в конфигурационном файле и в том, как он обращается к каталогам в среде Docker.
Я также попробовал выполнить: docker system prune -a --volumes
<Сообщение об ошибке:
web_container | Traceback (most recent call last):
web_container | File "/code/./docker/projectile/projectile/wsgi.py", line 16, in <module>
web_container | application = get_wsgi_application()
web_container | File "/usr/local/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
web_container | django.setup(set_prefix=False)
web_container | File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 19, in setup
web_container | configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
web_container | File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
web_container | self._setup(name)
web_container | File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
web_container | self._wrapped = Settings(settings_module)
web_container | File "/usr/local/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
web_container | mod = importlib.import_module(self.SETTINGS_MODULE)
web_container | File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
web_container | return _bootstrap._gcd_import(name[level:], package, level)
web_container | ModuleNotFoundError: No module named 'projectile'
web_container | unable to load app 0 (mountpoint='') (callable not found or import error)
Мой файл uwsgi.ini
[uwsgi]
socket=app.sock
master=true
# maximum number of worker processes
processes=4
threads=2
# Django's wsgi file
module=docker.projectile.projectile.wsgi:application #<----- FAILING
# chmod-socket=664
# uid=www-data
# gid=www-data
# clear environment on exit
vacuum = true
Мой Dockerfile
FROM python:3.9.6
# Environment varialbes
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED=1
# Install Poppler (requirement from Pdf2Image)
RUN apt-get update
RUN apt-get install poppler-utils -y
# Workdir
WORKDIR /code
# Requirements
COPY ./docker/projectile/requirements.txt /code/
RUN pip install -r requirements.txt
# Copy codebase to Docker
COPY . /code/
# Ports to expose
EXPOSE 80
Мой docker-compose.yml
version: "3.9"
services:
web:
container_name: web_container
build:
context: .
dockerfile: ./docker/projectile/Dockerfile
restart: always
volumes:
- .:/code
ports:
- "8000:8000"
command: uwsgi --ini ./docker/projectile/uwsgi.ini
#command: python3 docker/projectile/manage.py runserver 0.0.0.0:8000
nginx:
container_name: nginx-container
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
restart: always
ports:
# - "8080:80"
- "80:80"
volumes:
- .:/code
- ./log:/var/log/nginx
depends_on:
- web
Обзор моего репозитория
my-app/
┣ docker/
┃ ┣ nginx/
┃ ┃ ┣ Dockerfile
┃ ┃ ┣ my_nginx.conf
┃ ┃ ┣ nginx.conf
┃ ┃ ┗ nginx_origin.conf
┃ ┣ projectile/ <------------ The app I'm trying to run
┃ ┃ ┣ imagefile/
┃ ┃ ┃ ┣ __pycache__/
┃ ┃ ┃ ┣ migrations/
┃ ┃ ┃ ┣ templates/
┃ ┃ ┃ ┣ __init__.py
┃ ┃ ┃ ┣ admin.py
┃ ┃ ┃ ┣ apps.py
┃ ┃ ┃ ┣ exceptions.py
┃ ┃ ┃ ┣ models.py
┃ ┃ ┃ ┣ serializers.py
┃ ┃ ┃ ┣ tests.py
┃ ┃ ┃ ┣ urls.py
┃ ┃ ┃ ┗ views.py
┃ ┃ ┣ projectile/
┃ ┃ ┃ ┣ __pycache__/
┃ ┃ ┃ ┣ .env
┃ ┃ ┃ ┣ .env.example
┃ ┃ ┃ ┣ __init__.py
┃ ┃ ┃ ┣ asgi.py
┃ ┃ ┃ ┣ settings.py
┃ ┃ ┃ ┣ urls.py
┃ ┃ ┃ ┗ wsgi.py <----------------- WSGI file
┃ ┃ ┣ Dockerfile
┃ ┃ ┣ __init__.py
┃ ┃ ┣ db.sqlite3
┃ ┃ ┣ manage.py
┃ ┃ ┣ requirements.txt
┃ ┃ ┣ uwsgi.ini <-------------- uWSGI init file I'm invoking to run server
┃ ┃ ┗ uwsgi_params
┃ ┗ __init__.py
┣ log/
┃ ┣ access.log
┃ ┗ error.log
┣ .gitignore
┣ README.md
┣ app.sock
┗ docker-compose.yml