MLOps Academy · Lesson

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

  1. Write a Dockerfile for a Model API
  2. Slim Images with Multi-Stage Builds
  3. Pass Config via Environment Variables
  4. Run and Test the Container Locally
← Back to MLOps Academy