Run Tests in Their Own Build Stage
Labs have no container engine, so nothing is built: your files are checked by reading them.
The image of invoicer installs requirements-dev.txt (pytest, linters, 180 MB) and runs the tests while building, so every production image carries the test tools.
Restructure /home/student/projects/invoicer/Dockerfile into three stages, so that CI can run docker build --target test . and then ship docker build .:
| Stage | Based on | Does |
|---|---|---|
base | python:3.12-slim | WORKDIR /app, installs requirements.txt only, copies the source |
test | base | installs requirements-dev.txt and runs pytest -q |
| runtime (the last stage) | base | sets the CMD; no dev requirements, no tests |
The runtime stage must not depend on the test stage in any way.
About this machine
Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.
Part of Docker Fundamentals. Next step: Stop Re-Downloading Packages on Every Build
Teaching or writing about this? Embed this lab on your page
Your machine is ready to start
A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.
No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.