Docker Community Forums

Share and learn in the Docker community.

Docker Compose and Python

I have imported my entire project into docker, and I am getting a

ModuleNotFoundError

from one of the modules I have created.

FROM python:3.8
WORKDIR /workspace/
COPY . .
RUN pip install pipenv
RUN pipenv install --deploy --ignore-pipfile
#EXPOSE 8000
#CMD ["pipenv", "run", "python", "/workspace/bin/web.py"]

I tried looking around for answers, but I cannot seem to get it working.

commands:

docker build -t atletico .
docker run -p 8000:8000 atletico

Docker Build:
https://pastebin.com/FXMrY2En

Traceback (most recent call last):
  File "/workspace/bin/web.py", line 3, in <module>
    from bin.setup import setup_app
ModuleNotFoundError: No module named 'bin'

A copy of my directory:

├── Dockerfile
├── Pipfile
├── Pipfile.lock
├── README.md
├── bin
│   ├── __init__.py
│   ├── __pycache__
│   │   └── web.cpython-38.pyc
│   ├── setup.py
│   └── web.py
├── docker-compose.yml
├── frio
│   ├── __init__.py
│   ├── __pycache__
│   │   └── __init__.cpython-38.pyc
│   ├── app_events.py
│   └── config.py
├── routes
│   ├── __init__.py

docker-compose.yml:

version: '3'
services:
  db:
    image: postgres:12
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=test_db
  redis:
    image: "redis:alpine"
  web:
    env_file:
      - .env.local
    build: .
    ports:
      - "8000:8000"
    volumes:
      - .:/workspace
    depends_on:
      - db
      - redis
    command: "pipenv run python /workspace/bin/web.py"

The issue was that I did not set up a PYTHONPATH.