docker python custom module not found

I am new to docker and trying to move one simple application to docker.
Python standard modules I am able to import using “pip install”. However, I have some custom python utility files that I would like to use.
These files are in separate package “utils”.

In my main python file : test.py, I am doing

  • Docker 1.12 Port Fowarding Services Across Nodes
  • Docker Image move to the src directory
  • How to create notification for success application deployment in ECS Docker?
  • What is the default admin password for DRONE_ADMIN users?
  • Access Docker forwarded port on Mac
  • Disable CSS and Javascript cache in nginx server created with Docker
  • from utils import math.py, logger.py
    

    This outside of docker works fine, but when running through docker gives me the error "ImportError: No module named utils".

    My Dockerfile code:

    FROM python:2.7.11
    ADD ./ test_project/
    WORKDIR test_project
    ENV PATH=$PATH:/test_project/utils
    ENV PYTHONPATH /test_project/utils
    
    CMD [ "python", "report/test.py"]
    

    My directory structure:

    • test_project
      • report
      • utils

    Any suggestions?

  • Can't communicate client with Docker(Centos 7) + DNS Server(Container Ubuntu 14.04) with Virtual Box
  • How to mount network Volume in Docker for Windows (Windows 10)
  • Sharing /etc/passwd between two Docker containers
  • How to add --restart='always' to container already created
  • Determine if docker image built locally or pulled from repo?
  • Use docker or custom AMI in Amazon ElasticBeanstalk
  • One Solution collect form web for “docker python custom module not found”

    You set PYTHONPATH to /test_project/utils. When trying resolve the module utils, it is looking for one of:

    • file /test_project/utils/utils.py
    • directory /test_project/utils/utils/ that contains __init__.py.

    It looks like you have this?

    utils/math.py
    utils/logger.py
    

    I wonder if what you really mean to do is

    # different path...
    ENV PYTHONPATH /test_project
    
    from utils import math
    from utils import logger
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.