Containerization, Multi-Stage Docker & Security Hardening
CSC3119 · Lab

Docker Multi-Stage Build & Image Layer Optimizer

Build the stroke API image four ways and compare size, rebuild time and attack surface. Small, fast and non-root isn't a style choice — it's what passes a hospital security review.

  1. 1 · Predict0/1
  2. 2 · Experiment0/2
  3. 3 · Explain0/1
  4. 4 · Code it0/1
  5. 5 · Challenge
  6. 0/4 tasks done

Predict first

Commit to a guess before you touch anything. Being wrong here is how it sticks.

A 1,200 MB image becomes 160 MB after a multi-stage build. By what percentage did it shrink?

Experiment

Move the controls and watch the outputs. Goals tick off automatically when you reach them.

Dockerfile choices

Image size
1315 MB
Rebuild after a code change
110 s
Security grade
F

gcc and build tools are in the production image — extra size and extra attack surface.

Explain it

Put what you saw into words. This is what the exam will ask you to do.

Why use multi-stage builds for Python ML APIs, and why never run the container as root?

Code it

Write real code against real data. Python and SQL run right here in your browser and hidden tests check your work; the AI reviews it like an examiner.

Write & reviewexam

A production Dockerfile

Write the Dockerfile for the stroke FastAPI service (app/, models/, requirements.txt). Requirements: multi-stage build with no compilers in the final image, a slim base, dependency layer caching, a non-root user, no secrets baked in, a health check, and Uvicorn on port 8000. Also list what goes in .dockerignore as a comment.

Ctrl/⌘ + Enter to run

Challenge

Fixed variations, a new problem every day, and unlimited AI challenges built from your current settings.

AWS EC2 On-Demand vs Spot Cost Delta

An m5.xlarge instance costs $0.192 per hour On-Demand. For fault-tolerant batch stroke retraining, AWS Spot instances offer a 72% discount. What is the Spot price per hour in dollars? (3 decimals)