Help us learn about your current experience with the documentation.
Take the survey.
Tutorial: Scan a Docker container for vulnerabilitiesYou can use container scanning to check for vulnerabilities in container images stored in the container registry.
Container scanning configuration is added to the pipeline configuration of a project. In this tutorial, you:
Dockerfile
file to the project. This Dockerfile
contains minimal configuration required to create a Docker image.Dockerfile
, build and push a Docker image to the container registry, and then scan the Docker image for vulnerabilities.To create the new project
Tutorial container scanning project
.Dockerfile
to new project
To provide something for container scanning to work on, create a Dockerfile
with very minimal configuration:
In your Tutorial container scanning project
project, select plus > New file.
Enter the filename Dockerfile
, and provide the following contents for the file:
Docker images created from this Dockerfile
are based on hello-world
Docker image.
Now you’re ready to create pipeline configuration. The pipeline configuration:
Dockerfile
file, and pushes the Docker image to the container registry. The build-image
job uses Docker-in-Docker as a CI/CD service to build the Docker image.Container-Scanning.gitlab-ci.yml
template, to scan the Docker image stored in the container registry.To create the pipeline configuration:
In the root directory of your project, select plus > New file.
Enter the filename .gitlab-ci.yml
, and provide the following contents for the file:
include:
- template: Jobs/Container-Scanning.gitlab-ci.yml
container_scanning:
variables:
CS_IMAGE: $CI_REGISTRY_IMAGE/tutorial-image
build-image:
image: docker:24.0.2
stage: build
services:
- docker:24.0.2-dind
script:
- docker build --tag $CI_REGISTRY_IMAGE/tutorial-image --file Dockerfile .
- docker login --username gitlab-ci-token --password $CI_JOB_TOKEN $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE/tutorial-image
Select Commit changes.
You’re almost done. After you commit the file, a new pipeline starts with this configuration. When it’s finished, you can check the results of the scan.
Check for reported vulnerabilitiesVulnerabilities for a scan are located on the pipeline that ran the scan. To check for reported vulnerabilities:
container_scanning
in the test
stage.container_scanning
job was successful, select the Security tab. If any vulnerabilities were found, they are listed on that page.A Docker image based on hello-world:latest
is unlikely to show any vulnerabilities. For an example of a scan that reports vulnerabilities:
Dockerfile
file.FROM hello-world:latest
with a different Docker image for the FROM
instruction. The best Docker images to demonstrate container scanning have:
After you commit changes to the file, a new pipeline starts with this updated Dockerfile
. When it’s finished, you can check the results of the new scan.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4