Docker ENV for Python variables

Within your python code you can read env variables like:

import os
username = os.environ['MY_USER']
password = os.environ['MY_PASS']
print("Running with user: %s" % username)

Then when you run your container you can set these variables:

docker run -e MY_USER=test -e MY_PASS=12345 ... <image-name> ...

This will set the env variable within the container and these will be later read by the python script (test.py)

More info on os.environ and docker env

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)