When using python, if there is an environment variable, I want to set its value, if not, the default value
Access environment variables from Python
import os
url = os.getenv("YOUR_URL", "http://qiita.com")
print(url)
os.environ.get
os.environ is like a map, so
## When trying with docker
$ docker run -v $PWD:/work --rm python:2.7.12 python /work/sample.py http://qiita.com $ docker run -e YOUR_URL="http://127.0.0.1" -v $PWD:/work --rm python:2.7.12 python /work/sample.py http://127.0.0.1
Recommended Posts