I'm trying to set up imports inside docker container, so they behave the same way as in the manually executed script.
Project tree:
.
┣ StatisticManager
┃ ┣ resources
┃ ┃ ┣ data.db
┃ ┃ ┣ data.csv
┃ ┃ ┗ index.html
┃ ┣ scraper.py
┃ ┣ Dockerfile
┃ ┗ requirements.txt
┣ WebService
┃ ┣ templates
┃ ┃ ┗ plot.html
┃ ┣ app.py
┃ ┣ Dockerfile
┃ ┗ requirements.txt
┗ docker-compose.yaml
I'm using from StatisticManager.scraper import Database
in app.py
That's where ModuleNotFoundError
occurs after the container is composed up with docker-compose.yaml
StatisticManager/Dockerfile:
FROM python:3.9.1
RUN mkdir -p /usr/src/app/
WORKDIR /usr/src/app/
COPY . /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
CMD ["python", "scraper.py"]
WebService/Dockerfile:
FROM python:3.9.1
RUN mkdir -p /usr/src/app/
WORKDIR /usr/src/app/
COPY . /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000
CMD ["python", "app.py"]
docker-compose.yaml:
version: "3"
services:
scraper:
build: StatisticManager/
restart: always
volumes:
- db_volume:/usr/src/app
web_service:
build:
context: WebService/
restart: always
ports:
- 5000:5000
environment:
- TZ=Europe
depends_on:
- "scraper"
volumes:
db_volume: