Authorized DevOps and container security practice
Build a commit-tagged image and scan it
Connect a registry build to GitLab Container Scanning and read the job report as scoped evidence.
Learning objective
Build and push the authorized commit’s image, scan that same image reference, and report what the scan did and did not establish.
Use only a repository, branch, runner, registry, image, and activity you own or have explicit authorization to review. Use a Gemini tool only with sanitized material your organization approves. The website does not connect to Gemini.
Check runner and registry prerequisites
Before adding a container job, confirm that the approved project runner can run the chosen builder. GitLab’s container-scanning workflow requires a Linux runner using a Docker or Kubernetes executor, a supported image, a test stage, and an image already available in the GitLab Container Registry. A Docker-in-Docker example also requires the runner owner to configure that mode safely; do not try to enable privileged execution yourself.
The snippet below is a bounded example for an approved disposable project. It logs in with GitLab’s predefined registry variables, builds the current commit, and pushes a tag made from CI_COMMIT_SHA. The official Container Scanning template runs in the test stage and receives the same image reference through CS_IMAGE. Keep credentials in protected CI/CD variables or predefined variables; never print a token into a job log.
Read the scan result and its limits
Inspect the build-container job log and confirm the exact commit tag was pushed. Then open the container_scanning job, review its status, and download its security report artifact. Record the image reference or digest and the findings the scanner actually reports.
A completed scan with no findings means that this scanner found no reportable matches within its coverage and inputs. It does not prove the image is risk-free, identify every application flaw, or replace review of the base image, runtime identity, build context, and secret-handling path. A missing or skipped scan job is not a clean result.
Controlled examples
Adapt examples only inside your approved project
include:
- template: Jobs/Container-Scanning.gitlab-ci.yml
stages:
- build
- test
variables:
CS_IMAGE: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA"
build-container:
stage: build
image: docker:cli
services:
- name: docker:dind
alias: docker
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
script:
- echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" --username "$CI_REGISTRY_USER" --password-stdin
- docker build --pull --tag "$CS_IMAGE" .
- docker push "$CS_IMAGE"Controlled practice
Apply the lesson
Training scenario
The training project owner approved one disposable registry namespace and one feature branch. The assigned runner is already configured for the approved container build method.
- Confirm the runner, registry namespace, supported target image, and permitted push action with the owner.
- Add the GitLab scanning template and adapt the build job for the approved runner without exposing registry credentials in logs.
- Validate the pipeline configuration, then run it on the authorized feature branch.
- Compare the commit SHA in the build tag with CS_IMAGE and the image scanned by container_scanning.
- Open the security report and note the exact result; treat a missing or skipped scan as incomplete evidence.
Check your work: The authorized image is tagged to the current commit, the scanner runs against the same image, and the report artifact is available for review with its scope and limits recorded.
Learning check
Check your understanding
Which image reference gives the clearest link between this pipeline’s build and container scan?
Official references
Continue in the lesson sequence. Return to the GitLab and Gemini path.