4

I have a docker image that is running a gunicorn process, but everytime it runs I get the error ImportError: No module named 'crm'. So I am following this SO post to solve this issue.

However, when I run

ENTRYPOINT ["PYTHONPATH=`pwd`/..", "/usr/local/bin/gunicorn", "web_interface:app", "-w 4", "-t 90", "--log-level=debug", "-b 0.0.0.0:8000",  "--reload"]

the container spits back a

ERROR: for web  Cannot start service web: oci runtime error: container_linux.go:247: starting container process caused "exec: \"PYTHONPATH=`pwd`/.. \": stat PYTHONPATH=`pwd`/.. : no such file or directory"

Any idea how I can run the PYTHONPATH command?

I should state that it works locally on my Mac, but not in the Ubuntu container.

What I have tried:

"PYTHONPATH=pwd/.."

"PYTHONPATH=$(pwd)/.."

"PYTHONPATH=$PWD/.."

Andrew Graham-Yooll
  • 2,148
  • 4
  • 24
  • 49

2 Answers2

13

You should define the environment outside of the ENTRYPOINT with the ENV instruction:

ENV PYTHONPATH /absolute/path/to/the/pythonpath/inside/the/container
ENTRYPOINT ["/usr/local/bin/gunicorn", "web_interface:app", "-w 4", "-t 90", "--log-level=debug", "-b 0.0.0.0:8000",  "--reload"]
zigarn
  • 10,892
  • 2
  • 31
  • 45
  • Great, I like this answer better. So I could just use `$PWD/..` instead of the path name – Andrew Graham-Yooll Jun 26 '17 at 09:44
  • Not sure about the `$PWD` as it depends on the current `WORKDIR` (https://docs.docker.com/engine/reference/builder/#workdir). You're building an image so you have control on the paths, no need to be relative from your application dir. – zigarn Jun 26 '17 at 09:51
  • I used `ENV PYTHONPATH "${PYTHONPATH}:${PWD}"` and it works just fine. – Rafal Enden Nov 06 '18 at 11:05
0

So this seems to be working

ENTRYPOINT ["/usr/local/bin/gunicorn", "--pythonpath=`$PWD`/..", "web_interface:app", "-w 4", "-t 90", "--log-level=debug", "-b 0.0.0.0:8000",  "--reload"]
Andrew Graham-Yooll
  • 2,148
  • 4
  • 24
  • 49