Answer the question
In order to leave comments, you need to log in
How to fix ModuleNotFoundError: No module named 'mainpage' | Django + Gunicorn + docker-compose?
Hello. $ sudo docker-compose -f prod.yml up
I run , I get an error from the header when starting the gunicorn workers .
Here is my Dockerfile:
FROM python:buster
ENV PYTHONUNBUFFERED 1
COPY app /app
WORKDIR /app
RUN pip install -r requirements/prod.txt
version: '3'
volumes:
pgdata:
services:
web:
build:
context: .
dockerfile: docker/prod/python/Dockerfile
volumes:
- ./app:/app
ports:
- "8000:8000"
command: gunicorn -w 4 IRMback.IRMback.wsgi.application
- postgres
postgres:
image: postgres:10
environment:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASS: admin
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- 5433:5433
IRM
├── app
│ ├── backend
│ │ ├── api
│ │ ├── combinator
│ │ ├── crowler
│ │ ├── IRMback
│ │ │ ├── __init__.py
│ │ │ ├── settings.py
│ │ │ ├── urls.py
│ │ │ ├── views.py
│ │ │ ├── <b>wsgi.py</b>
│ │ ├── mainpage
│ │ ├── manage.py
│ │ └── ...
│ ├── frontend
│ │ └── ...
│ requirements
│ ├── base.txt
│ ├── local.txt
│ └── prod.txt
│ docker
│ ├── local
│ └── Dockerfile
│ ├── prod
│ └── Dockerfile
├── docker-compose.yml
└── prod.yml
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'allauth',
'allauth.socialaccount',
'allauth.socialaccount.providers.vk',
'allauth.socialaccount.providers.google',
'allauth.account',
'rest_auth.registration',
'corsheaders',
'mainpage',
'combinator'
]
WSGI_APPLICATION = 'IRMback.wsgi.application'
manage.py runserver
runs fine. manage.py runserver
starts normally. That is, I dare to assume that the matter is in Gunicorn. IRMback.IRMback.wsgi.application
in prod.yml. Do I need to shove wsgi into each app? Where to read about it? Prolonged googling errors did not give satisfactory results.
Answer the question
In order to leave comments, you need to log in
Problem solved. It turns out that the reason was in my Dockerfile.
It turns out that the peculiarity of Gunicorn is that WORKDIR should lead to the same place where manage.py is located.
So, by fixing WORKDIR /app
on WORKDIR /app/backend
and deleting one IRMback
of the prod.yml
, the problem was solved.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question