Hard-coded color (initial example)
A typical Flask app that hard-codes the color looks like this:Read color from an environment variable
Update the app to read from an environment variable namedAPP_COLOR, with a sensible default:
Run locally with different colors
You can set the environment variable before running, or inline for a single command:Build and run in Docker
When you package the application into a Docker image (for example,simple-webapp-color), pass the environment variable into the container at runtime using -e:
APP_COLOR value for each docker run invocation.
Quick reference: common commands
Using environment variables for configuration keeps code and deployment concerns separate and makes it easy to change behavior across environments without modifying the application.
Inspecting environment variables in a container
To see which environment variables are set inside a running container, usedocker inspect. The container properties include a Config.Env section that lists environment variables.
A full docker inspect <container-id> will include JSON like this:
{{json .Config.Env}} in backticks when including it in MDX or other contexts that may interpret curly braces.
Why environment variables?
- Simple and language-agnostic: Most runtimes expose environment variables easily.
- Secure for secrets when used with secret managers (avoid committing secrets to source code).
- Works well with containers and orchestration platforms (Docker, Kubernetes, etc.).
- Allows different settings per environment without code changes.
Links and references
- Python Basics
- Docker Training Course for the Absolute Beginner
- Docker documentation: https://docs.docker.com/