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.
More on Write-a-Dockerfile tasks
Write a production Dockerfile for a Node.js API using a multi-stage build.IntermediateWrite a Dockerfile for a Python Flask app that runs with gunicorn as a non-root user.BeginnerWrite a Dockerfile for a Go service that produces a tiny image (under 20 MB).IntermediateWrite a multi-stage Dockerfile for a Java Spring Boot app built with Maven.IntermediateWrite a Dockerfile for a static React site served by Nginx.BeginnerThis Dockerfile rebuilds dependencies on every code change. Fix it.Beginner