Andrew Graham-Yooll
Andrew Graham-Yooll

Reputation: 2258

Setting PYTHONPATH in Ubuntu 16.04 for a Docker image to run properly

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

Upvotes: 4

Views: 8444

Answers (2)

zigarn
zigarn

Reputation: 11605

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

Upvotes: 13

Andrew Graham-Yooll
Andrew Graham-Yooll

Reputation: 2258

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

Upvotes: 0

Related Questions