I'm writing a docker script for running a python program from bitbucket, say myprogram.py. The python program uses specific functions from other files in other directories, and calls them like this:
from mydirectory.myfunction import MyFunction
Normally, if I just clone the bitbucket repository and run it, no errors occur.
My repo in bitbucket consists of the program, a docker file and some directories with scripts of functions. So I clone the repo, and then build.
When I tried to build it, it was succesful. I build it with this command:
docker build -t myprogram .
However, when I use the command (the -h is the "help" option made with argparse just to see if the program is able to run with an option):
docker run --rm -it myprogram -h
it gives me the error:
Traceback (most recent call last):
File "/usr/src/myprogram.py", line 8, in <module>
from mydirectory.myfunction import MyFunction
ImportError: No module named 'mydirectory'
What is the best way to implement in the docker file, that the program uses functions from other scripts in other directories in the same repo in bitbucket? I'm new to docker, so any help would be appreciated! Please let me know if you need any additional information.
My dockerfile looks like this:
FROM debian:stretch
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -qq; \
apt-get install -y -qq git \
apt-utils \
wget \
python3-pip \
ncbi-blast+ \
libz-dev \
; \
rm -rf /var/cache/apt/* /var/lib/apt/lists/*;
ENV DEBIAN_FRONTEND Teletype
# Install python dependencies
RUN pip3 install -U numpy
COPY myprogram.py /usr/src/myprogram.py
RUN mkdir /mydirectory
COPY mydirectory/* /mydirectory/
RUN chmod 755 /usr/src/myprogram.py; \
WORKDIR /workdir
# Execute program when running the container
ENTRYPOINT ["/usr/src/myprogram.py"]
mydirectoryinto the container. Maybe that's why python is unable to find it.