Get a quick overview from an SPDX file
In this step, you will learn how to obtain a quick overview of the software components within a Docker image by generating and examining an SPDX (Software Package Data Exchange) file. SPDX is an open standard for communicating software bill of materials (SBOM) information, including components, licenses, and copyrights.
Generating an SPDX file for a Docker image requires a tool that can analyze the image layers and extract the necessary information. One such tool is syft
, a command-line tool for generating SBOMs from container images and filesystems.
Since syft
is not pre-installed, we will download and install it. We will download the latest release for Linux.
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sudo bash -s -- -b /usr/local/bin
This command downloads the installation script for syft
and executes it with sudo
to install the binary to /usr/local/bin
. You might be prompted for your password, but the labex
user has passwordless sudo
.
After installation, you can verify that syft
is installed by checking its version:
syft version
You should see the version information for syft
.
Now, let's generate an SPDX file for the my-recent-image
we built in the previous step. We will output the result to a file named my-recent-image.spdx.json
in the ~/project
directory.
syft my-recent-image -o spdx-json > ~/project/my-recent-image.spdx.json
This command tells syft
to analyze the my-recent-image
and output the results in SPDX JSON format, redirecting the output to the specified file. This process might take a moment depending on the size of the image.
Once the command completes, you will have an SPDX JSON file containing a detailed inventory of the software packages found within the image. You can view the contents of this file using a text editor like nano
:
nano ~/project/my-recent-image.spdx.json
Inside the file, you will find information about the image itself and a list of packages detected, including their names, versions, and licenses. This provides a quick overview of the software components present in your image without needing to run the container or inspect individual layers manually.
You can scroll through the file to see the different sections and the information they contain. Look for the packages
array, which lists the detected software components.
Press Ctrl + X
to exit nano
.