Interview Prep/Real-World Interview/Write-a-Dockerfile tasks

Write a Dockerfile where the app's config differs per environment without rebuilding.

BeginnerHands-onWrite-a-Dockerfile tasks
Answer
FROM python:3.12-slim
WORKDIR /app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
ENV APP_ENV=production LOG_LEVEL=info
CMD ["python", "app.py"]
docker run -e APP_ENV=staging -e LOG_LEVEL=debug -v ./staging.yaml:/app/config.yaml:ro myapp:1.4.2

Key trick → ENV sets defaults and the runtime -e (or Kubernetes env/ConfigMap) overrides them. The same image digest then runs everywhere.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Dockerfile tasks