I am trying to have my python application running on a PEX file, inside a docker container.
I was wondering if PEX files support any kind of configuration in order to read environment variables that get provided to the docker container just to avoid packaging a PEX file per deplyoment environment having differrrent types of configuration.
I couldn't find any type of documentation on this on the PEX site.
Expectation was to be able to consume defined environment variables for the docker container from the python process running on the PEX file, but the PEX execution seems self-isolated.
Only documentation about runtime environment variables I could find is about PEX_* environment variables which doesn't seem to serve that purpose.
PEX programs receive all environment variables (except possibly for a few changes, e.g. in
PYTHONPATH), you can try this by writingimport os; print(sorted(os.environ.items()))tomyprog.py, and then runningpython myprog.py, buildingmyprog.pex, runningpython myprog.pex. An even more specific way to try:Docker with the
docker runcommand doesn't pass host environment variables to the container. To pass some of them, use the-eflag (e.g.docker run -e ANSWER=42 ...), like this: https://stackoverflow.com/a/30494145/97248