Docker Community Forums

Share and learn in the Docker community.

How to read environment variables from YAML file in docker?

I’m having a .env file that contains variables

VALUE_A=10
NAME=SWARNA

I’m having an env.yml file.

Information:
   value: $VALUE_A
   name: $NAME

I’m having a python file envpy.py

from envyaml import EnvYAML

# read file env.yml and parse config
env = EnvYAML('env.yml')

print(env['Information']['value'])

print(env['Information']['name'])

Here is my Dockerfile

FROM python:3
ADD envpy.py /
ADD env.yml /
RUN pip install envyaml
CMD [ "python", "./envpy.py" ]

Expected output:

10
SWARNA

But I got :

VALUE_A
NAME

How to print the values. Please correct me or suggest me where I’m doing wrong. Thank you.

How do you use that .env file? You shouln’t get the name of the variables if you read environment variables from python. I tried the Dockerfile and the python file and it works as expected if the variables are right