简体   繁体   中英

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

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

所以这似乎有效

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM