Prerequisites
- Docker installed locally
- Trivy image cache volume (
$WORKSPACEmapped to/root/.cache/) - A Spring Boot JAR artifact in
target/*.jar
1. Scan the Current Base Image
First, scanmyorg/numeric-app:latest:
2. Compare Alternative Base Images
We’ll evaluate these images:openjdk(latest)openjdk:8openjdk:8-alpineadoptopenjdk/openjdk8:alpine-slim
2.1 Summary of Scan Results
Using the
latest tag can introduce unexpected changes. Always pin to a specific version for production.3. Detailed Scan Examples
3.1 openjdk (latest)
3.2 openjdk:8
3.3 openjdk:8-alpine
3.4 adoptopenjdk/openjdk8:alpine-slim
We choose adoptopenjdk/openjdk8:alpine-slim for its zero vulnerabilities and fixed version on Alpine Slim.
4. Update the Dockerfile
Switch the base image:5. Jenkins Pipeline Configuration
In yourJenkinsfile, ensure you have Trivy and Docker build stages:
Using
sudo resolves permission issues on the Trivy cache directory. Alternatively, add the Trivy cache folder to .dockerignore.