Objective: containerize the Python VWCE example from Lecture 6, including its pytest suite. Build a Docker image from scratch (no pre-made course image), run the app and tests inside the container, and optionally convert to Apptainer for HPC. Keep a lab log (codes/lab07/lab-notebook.md) with build/run commands and notes.
Exercise 1 — Prep and copy sources¶
In your
sspa-sandbox, createcodes/lab07/<name.surname>/.Copy the Lecture 6 Python materials (source + tests you wrote) into that folder:
cp -r /path/to/lab06/<name.surname>/python codes/lab07/<name.surname>/.Confirm the code and tests still run on the host:
pytest -q.
Exercise 2 — Write the Dockerfile from scratch¶
Create
Dockerfileincodes/lab07/<name.surname>/with a small base (e.g.,python:3.11-slim).Add a non-root user, set
WORKDIR, copy the code, install Python deps (at leastpytest; pin versions viarequirements.txtif you have one), and set a sensible defaultCMD(e.g.,["python", "-m", "main", "--csv", "vwce_2024.csv"]).Add a build target or stage for tests so you can run
pytestinside the image without polluting the final runtime layer. Document the target name (e.g.,--target test).Include a
.dockerignoreto keep images lean (no__pycache__,.git, large CSVs if unnecessary).
Exercise 3 — Build and run¶
Build the runtime image:
docker build -t vwce:latest .Run the app with a bind mount for your working directory:
docker run --rm -v "$PWD":/app -w /app vwce:latest python -m main --csv vwce_2024.csv --out /app/out.datVerify output and logs; capture the command and output snippet in your notebook.
Exercise 4 — Run tests inside the container¶
Execute the test stage/target:
docker build -t vwce:test --target test .ordocker run --rm vwce:latest pytest -q.Confirm the suite passes; if it fails, fix code/tests and rebuild.
Record failing/passing outputs in the notebook, along with the final commands used.
Exercise 5 — Optional: Apptainer for HPC¶
If Apptainer is available, convert your Docker image:
apptainer build vwce.sif docker-daemon://vwce:latestRun the CLI inside the
.sif:apptainer exec vwce.sif python -m main --csv vwce_2024.csv.Note any path binding requirements (
-B) or permission quirks in the notebook.
Submission checklist¶
codes/lab07/<name.surname>/Dockerfile(and.dockerignore/requirements.txtif used) plus the Python source/tests.lab-notebook.mdwith build/run commands, outputs, and any issues.Runtime image runs the VWCE script; test stage/command runs pytest successfully. Optional
.sifif you tried Apptainer.