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 :, I am doing

  • How to obtain Docker image ID from API after building?
  • Can't attach terminal to a running container in docker
  • teamcity and docker integration
  • How do I push and pull from docker hub in Jenkins declarative pipeline
  • Cassandra cluster manager (ccm) on docker
  • Connect to a remote database on a docker container hosted on an AWS instance
  • from utils import,

    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/"]

    My directory structure:

    • test_project
      • report
      • utils

    Any suggestions?

  • What's the main advantage of using replicas in Docker Swarm Mode?
  • Docker-client Java: How to keep instances running?
  • Pagecache and dirty pages in paused container
  • error 28105#0: *1 FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream
  • Run command to docker container in a script
  • writing liberty logs directly to graylog
  • 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/
    • directory /test_project/utils/utils/ that contains

    It looks like you have this?


    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.