App-Level Environment Variables not available in Python app but available in python command line.


I have deployed an app through docker and the env variables are set through App-level Environment variable option.

When i tried to get print(os.getenv(“key”)) in the python application file (say,, i am getting “None” value as output in the browser. However if i get into docker exec -it /bin/bash and exectute the same commands it works fine. Infact i tried running the samefile by prefixing #python3 it works perfectly fine. any ideas why its not working when i access the file through browser?

Breaking my head for the past two days. every help would be appreciated.

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Taha Fatima
DigitalOcean Employee
DigitalOcean Employee badge
March 8, 2022

Hi @rkrk

I assume you are facing issues while accessing the defined environment variables in your app when using a Dockerfile.

Environment variables are only available as build-args for Dockerfile builds in App Platform. So you should declare them in the Dockerfile as an ARG and then set the ENV variable in the Dockerfile from the build-arg.

If for example you set APP_VAR environment variable in application spec file or via App Platform UI, then something like this may work to actually pass that value into the container. You need to add the below lines in Dockerfile.


Here’s a community link on the same and I assure you it works:

I hope this helps!

Cheers, Taha Fatima

Bobby Iliev
Site Moderator
Site Moderator badge
March 8, 2022


When defining your environment variables you need to make sure that you’ve set the scope to RUN_TIME and not only BUILD_TIME as described here:

That way the environment variables will be available not only during the build stage but also during the run time of your app.

Let me know how it goes.