Sub topic 7
Comparing image versions with docker scout compare
This chapter assumes you can run docker scout cves and read its output, and that you know what a CVE and a fixed version are. You should also be comfortable building and tagging Docker images.
Why compare two versions
A single scan tells you what is wrong with one image. It does not tell you whether a change made things better or worse. After you update a base image or add a dependency, the useful question is: what changed?
docker scout compare answers that. It analyzes two images and reports the differences in packages and vulnerabilities. The image you name as the baseline is the reference point. The other image is judged against it.
Running a comparison
The command takes the new image as an argument and the baseline in --to.
docker scout compare --to myapp:1.0 myapp:2.0Here myapp:1.0 is the baseline and myapp:2.0 is the image under review. The output has these parts:
- A summary of both images, including their digests and base images.
- Vulnerabilities that exist only in the new image, the ones you introduced.
- Vulnerabilities that exist only in the baseline, the ones you fixed.
- Packages that were added, removed, or changed version.
Vulnerabilities present in both images are unchanged, so they are not the focus of the report.
Reading the result
Start with the added findings. These are the regressions. For each one, check the severity and whether a fixed version exists, as you did with docker scout cves. A new critical finding with a fix available is a clear reason to rebuild before releasing.
Then look at the removed findings. They confirm that an update did what you wanted. If you switched base images to reduce vulnerabilities, a long removed list is your evidence.
Finally, look at the package changes. A new vulnerability usually traces back to a package that was added or upgraded. The package list tells you which change to question.
Choosing a baseline
The comparison is only as meaningful as the baseline. Good choices include:
- The image currently running in production.
- The previous release tag of the same application.
- The image built from the main branch, when you review a feature branch.
Comparing unrelated images produces a large, noisy diff that tells you little.
Using compare in a workflow
Run the comparison after every meaningful change to the Dockerfile or its dependencies. Attach the output to the pull request so reviewers can see the effect on security, not only on code. Later in this tutorial you will combine this with a severity gate in CI, so a build can fail when a change introduces serious findings.
Common mistakes
- Swapping the arguments. If you put the old image first and the new one in
--to, "added" and "removed" are reversed. Check which image is the baseline before you read the result. - Comparing different platforms. An amd64 image and an arm64 image can contain different packages. Compare like with like.
- Ignoring unchanged findings. A clean diff does not mean the image is safe. It means nothing got worse. Use
docker scout cvesto see the full list.
Exercise
You build myapp:2.0 after upgrading its base image. You run docker scout compare --to myapp:1.0 myapp:2.0. The report lists a high-severity CVE under "only in myapp:1.0". What does this mean, and does it need action?
Show answer
The CVE exists in the baseline but not in the new image, so the upgrade fixed it. It needs no action. The findings to review first are the ones listed as only in myapp:2.0, because those are the regressions.
Exercise
Why can the same compare command give different results when you run it a month later on the same two images?
Show answer
Scout matches package contents against vulnerability data that is updated continuously. New advisories can add findings to either image, even though the images themselves have not changed.