Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
advanced Premium CI/CD · ⏱ 50 min

Build a Secure GitLab Docker Pipeline

Scenario

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

  1. Download and unzip the lab.
  2. Review the app + starter .gitlab-ci.yml. You can validate the scan/SBOM/gate stages locally without a GitLab runner using the provided run-local.sh.

Instructions

Full instructions are part of Individual Pro

Unlock the step-by-step instructions, the solution guide, validation scripts, and downloadable files.

Unlock with Pro

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 completed
  • 1 — Validation failed
  • 2 — Required dependency missing
  • 3 — Lab environment not running
  • 4 — Configuration error
  • 5 — 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.

Upgrade to Pro

Reset the lab

  • docker compose down -v && docker compose up -d from 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.

Related labs