The CMD
of my dockerfile is this: ["python", "myproject/start_slide_server.py"]
However for this to work, I need to set the PYTHONPATH
to /app
, which is the parent directory of myproject
If I start the docker process and override CMD
with bash
, I can run the following
root@42e8998a8ff7:/app# export PYTHONPATH=.
root@42e8998a8ff7:/app# python myproject/start_slide_server.py
* Running on http://0.0.0.0:8090/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 236-035-556
And it works as expected
Now I add the line
RUN export PYTHONPATH=/app
before
CMD ["python" , "myproject/start_slide_server.py"]
it just failed
Traceback (most recent call last):
File "/app/myproject/start_slide_server.py", line 23, in <module>
from myproject import env
ImportError: No module named myproject
It seems like the RUN
line does not have any impact at all
I really do not want to define ENV
at the docker
command level because this PYTHONPATH
will not change from one image to next.
How can I achieve this?
I can use the ENV
directive
ENV PYTHONPATH /app
You should not over-write the
PYTHONPATH
with your path but append it; otherwise the system will not find the installed Python packages.RUN export PYTHONPATH="$PYTHONPATH:/app"
ENV PYTHONPATH="$PYTHONPATH:/app"