Sub topic 6
Choosing a better base image with recommendations
This chapter assumes you can run docker scout quickview and docker scout cves, and that you can read a Dockerfile FROM line. Both come from earlier chapters.
Why the base image matters
Most packages in an image come from its base image, the image named in the FROM line. Your own code usually adds only a small share. If the base is old or large, it can carry dozens of vulnerabilities that you never introduced. Changing the base is often the single largest fix available.
docker scout recommendations looks at the base image of the image you give it. It then suggests other tags that would reduce the vulnerability count.
Running the command
docker scout recommendations nginx:latestThe output has three parts:
- Target. The image you scanned and its detected base image.
- Refresh base image. Newer builds of the same tag or version you already use. This is the lowest-risk change, because the software version stays the same and only the patches are newer.
- Change base image. Different tags, such as a newer major version or a slimmer variant. Each suggestion lists how many vulnerabilities it removes, by severity, and how much the image size changes.
Docker Scout needs to know your base image. For images you built yourself, it can read provenance attestations, which are build metadata attached to the image. Without them, it may fall back to guessing from the image contents, and the result may be missing or wrong.
Applying a recommendation
Suppose the recommendations suggest a newer slim variant of Python. You edit the FROM line, rebuild, and scan again.
# Before
FROM python:3.9
# After
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "main.py"]docker build -t myapp:2.0 .
docker scout cves --only-severity critical0Always confirm the result with a new scan. The count the recommendation predicts is on the base image alone. Your application's own dependencies can add findings that the prediction does not include.
Trade-offs to check
A smaller or newer base is not always a safe swap.
| Change | Likely benefit | Possible cost |
|---|---|---|
| Refresh the same tag | Newer patches, same behavior | Almost none |
| Move to a `-slim` variant | Fewer packages, smaller size | Missing system libraries or tools |
| Move to a newer major version | Supported releases, more fixes | Breaking changes in the language or runtime |
| Move to a different OS family | Often very few packages | Different C library, which can break compiled dependencies |
Common mistakes
- Ignoring the refresh option. Teams often jump to a new major version when rebuilding the current tag would remove most findings.
- Trusting the output on images with no provenance. If the detected base looks wrong, build with attestations enabled or check the
FROMline yourself. - Stopping after the build. A successful build does not prove the vulnerabilities went away. Rescan.
Exercise
You run docker scout recommendations on your image. It offers a refresh of python:3.12-slim and a change to python:3.13-slim, which removes more vulnerabilities. Which do you try first, and what do you do after you edit the Dockerfile?
Show answer
Try the refresh of python:3.12-slim first. It keeps the same version, so the risk of breaking changes is lowest. After you edit the Dockerfile or pull the newer build, rebuild the image, run your tests, and rescan with docker scout cves to confirm the findings dropped. Consider python:3.13-slim only if the refresh does not remove enough, and test it separately.