skip to Main Content

I am building a python file that gives you the ETH balance from any crypto wallet. I want to do this by running the following Dockerfile:

FROM python:3.9.6

ADD main.py .

RUN pip freeze > requirements.txt
RUN pip install -r requirements.txt

CMD ["python", "main.py"]

main.py imports WalletData.py (containing web3 requests). This works just fine when I run main.py manualy but when I try to do it using the Dockerfile I get the error "ModuleNotFoundError: No module named ‘WalletData’". What can I do?

The workspace has the following structure

2

Answers


  1. I think you just forgot to add or copy your /app folder to container. Only main.py is added to container.

    Login or Signup to reply.
  2. Make sure to add all your files in docker container using COPY / ADD command, in case WalletData is custom module. You can also use pip install if you are using any third party modules/libraries

    eg for adding custom module to Docker Container using Dockerfile

    FROM python:3.9.6
    
    ADD /app .
    ADD main.py .
    ADD requirement.txt .
    
    
    RUN pip freeze > requirements.txt
    RUN pip install -r requirements.txt
    
    CMD ["python", "main.py"]
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search