简体   繁体   中英

Setting ENV variable from python script in dockerfile?

I'm trying to set an ENV equal to a python script output in my dockerfile. Due to layering, I'm unable to find a way to have them on the same layer. I've also been unable to find a way set the variable directly equal to the script, I can't seem to find how to run the script in the same line.

The python is a simple print, called test.py:

#!/usr/bin/env python

print("xd")

So far, I've tried a few versions of the below in my dockerfile to set the ENV to the script:

ENV testvar=test.py
ENV testvar=$(test.py)
ENV testvar='python test.py'

Is there anyway to set ENV testvar equal to the script in one step or a way to ensure the script and setting the variable are done on the same layer?

I ended up being able to place this in my entrypoint and set it to a k8's secret (also set in the entrypoint) to get it to other pods.

Another option that was tried was placing the script output into a txt file, setting the variable to that file, then deleting it.

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