0

I am trying to start a dockerized python flask application which i start with:

docker build -t python_offerte_test_v1:latest .
docker-compose up web_prod

this gives me the following error:

ModuleNotFoundError: No module named 'app'

My coworker says the he runs the exact same code and for him its working. However my /home/code is empty

my folder structure:


- DOCKER-PYTHON
    - offerte_scanner
       - server.py
    - app.py
    - docker-compose.yaml
    - Dockerfile

My dockerfile:

FROM python:3.8 as python

RUN pip install poetry
RUN mkdir /home/code
ADD ./* /home/code  

# install dependencies
RUN apt-get update \
  && apt-get -y install tesseract-ocr \ 
  && apt-get -y install ffmpeg libsm6 libxext6 # required for opencv\
  && apt-get libmagickwand-dev --no-install-recommends && rm -rf /var/lib/apt/lists/* \
  && apt-get pecl install imagick-6.9 \
  && apt-get docker-php-ext-enable imagick\
  && apt-get install tesseract-ocr-eng  #for english 


#init Poetry
WORKDIR /home/code

RUN poetry config virtualenvs.create false --local
RUN poetry install --only main
RUN apt-get update && apt-get -y install ghostscript && apt-get clean


#Set ImageMagick settings with policy.xml
RUN sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml

COPY policy.xml /etc/ImageMagick-6/

my docker-compose yaml:

version: '3'

services:
  web_prod:
    container_name: python_backend_offerte_scanner
    ports:
     - "5555:5000"
    volumes:
     - .:/code/home
    restart: always
    image: python_offerte_test_v1:latest
    working_dir: /code/home
    environment:
      IP_ELASTICSEARCH: <my ip>
    command: python -m gunicorn -w 2 -b 0.0.0.0:5555 app:app

my app.py:

from offerte_scanner.server import app

if __name__ == "__main__":
    app.run(host="0.0.0.0", debug=True)
Bruno Seriese
  • 27
  • 1
  • 7
  • 1
    Change `command: python -m gunicorn -w 2 -b 0.0.0.0:5555 app:app` to `command: cd /home/code && python -m gunicorn -w 2 -b 0.0.0.0:5555 app:app` The error you receive is that `app` is not found due you being in the wrong directory. Also your volume mapping is weird. You should only map a configuration file at most not the entire code again. Also you map `/code/home` but in your Dockerfile it is `/home/code`. There is a kogic error – Tin Nguyen May 11 '23 at 11:13
  • Yea the `Dockerfile` in the example is copying the files to `/home/code` but the `compose` is setting `working_dir: /code/home` – Skenvy May 11 '23 at 11:17
  • i changed this but now i get the error: " no module found: offertescanner" – Bruno Seriese May 11 '23 at 11:39

1 Answers1

0

It looks like it's a rather concise hint of what is wrong, which wouldn't be too complicated to solve.

In your main.py, try changing the debug parameter to False and see if it works.

this answer comes part from another answer.