Pass Config via Environment Variables
Keep model paths and secrets out of the image.
Do Not Bake Config In
Hardcoding a model path or API key bakes it into the image forever. Pass them as environment variables at run time instead.
Read Env in Python
Use os.getenv to read a variable, with a sensible default. Your code then bends to each environment without edits.
import os
model_path = os.getenv("MODEL_PATH", "/models/latest.pkl")All lessons in this course
- Write a Dockerfile for a Model API
- Slim Images with Multi-Stage Builds
- Pass Config via Environment Variables
- Run and Test the Container Locally