Build a Secure GitLab Docker Pipeline
Security wants every image gated before it ships. Build a `.gitlab-ci.yml` that builds and tags an image, scans it, generates an SBOM, pushes on success, and fails the pipeline when a high/critical vulnerability is present.
Learning objectives
- Build and tag the image
- Scan the image for vulnerabilities
- Generate an SBOM
- Push to a registry on success
- Fail the pipeline on defined severity
Before you start
Required software: Docker Engine 24+; a GitLab instance or gitlab.com project (optional to run end-to-end)
Prerequisites: Docker Image Engineering path, Docker Security path
- Download and unzip the lab.
- Review the app + starter
.gitlab-ci.yml. You can validate the scan/SBOM/gate stages locally without a GitLab runner using the providedrun-local.sh.
Instructions
Full instructions are part of Individual Pro
Unlock the step-by-step instructions, the solution guide, validation scripts, and downloadable files.
Hints
💡 Make the gate fail-closed
The scan step should exit non-zero on the chosen severity so the pipeline stops. With Trivy, use --exit-code 1 --severity HIGH,CRITICAL.
💡 SBOM
Generate a CycloneDX/SPDX SBOM (e.g. with Syft) as a build artifact so downstream consumers can audit dependencies.
Validate your work
From the lab folder, run:
bash validation/validate.sh The script reads only your local Docker state, never transmits data off your machine, and returns a status code:
0— Lab successfully completed1— Validation failed2— Required dependency missing3— Lab environment not running4— Configuration error5— Validation timed out
Note: validation targets Linux first. On Docker Desktop (macOS/Windows) some host-level checks (e.g. disk usage) may report differently; each script documents its limitations.
Solution
The full solution + troubleshooting explanation is available to Individual Pro members. Try to solve it first — that’s where the learning is.
Reset the lab
docker compose down -v && docker compose up -dfrom the original lab files restores the starting (broken) state.
Interview questions
- How do you make a CI scan step block a release?
- What is an SBOM and why generate one in CI?
- How should image tags be structured for traceability and rollback?
Finished this lab?
Sign in to record your completion and track progress across the path. Completion is recorded server-side.