O
O
Oleg Kotov2019-08-08 16:53:32
Django
Oleg Kotov, 2019-08-08 16:53:32

How to fix ModuleNotFoundError: No module named 'mainpage' | Django + Gunicorn + docker-compose?

Hello. $ sudo docker-compose -f prod.yml upI run , I get an error from the header when starting the gunicorn workers .
Here is my Dockerfile:

spoiler
FROM python:buster

ENV PYTHONUNBUFFERED 1

COPY app /app

WORKDIR /app

RUN pip install -r requirements/prod.txt

Here is my prod.yml:
spoiler
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

Here is the directory structure:
spoiler
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

Here is a piece of settings.py
spoiler
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'

Outside of docker via manage.py runserverruns fine.
In another docker config through the same one, it also manage.py runserverstarts normally. That is, I dare to assume that the matter is in Gunicorn.
Initially, there was the same error, but about the IRMback module. Fixed by adding the current path. IRMback.IRMback.wsgi.applicationin 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

1 answer(s)
O
Oleg Kotov, 2019-08-09
@AgeofCreations

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 /appon WORKDIR /app/backend
and deleting one IRMbackof the prod.yml, the problem was solved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question