docker: add distroless container build#17680
docker: add distroless container build#17680maxhuebler wants to merge 1 commit intoprometheus:mainfrom
Conversation
Signed-off-by: Max Huebler <max@huebler.us>
| ARG OS="linux" | ||
|
|
||
| # Stage: get CA certs and tzdata from a small Debian image | ||
| FROM debian:trixie-slim AS certs |
Check warning
Code scanning / Scorecard
Pinned-Dependencies Medium
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Final minimal image based on distroless static | ||
| FROM gcr.io/distroless/static:nonroot |
Check warning
Code scanning / Scorecard
Pinned-Dependencies Medium
jkataja
left a comment
There was a problem hiding this comment.
With the currently used distroless image, the output will not be as described. Instead it would need to be based on scratch to contain only the statically linked binary and minimal data.
| org.opencontainers.image.licenses="Apache License 2.0" | ||
|
|
||
| # Copy CA certs and timezone data from certs stage | ||
| COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt |
There was a problem hiding this comment.
Turns out the GoogleContainerTools distroless image already includes CA certs and TZ data. This is only required with scratch.
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Final minimal image based on distroless static | ||
| FROM gcr.io/distroless/static:nonroot |
There was a problem hiding this comment.
The first stage is not required with this image. Using scratch will produce the most minimal image.
|
|
||
| # Final minimal image based on distroless static | ||
| FROM gcr.io/distroless/static:nonroot | ||
|
|
There was a problem hiding this comment.
The parameters need to be added to this stage
| ARG ARCH | |
| ARG OS |
| COPY npm_licenses.tar.bz2 /npm_licenses.tar.bz2 | ||
|
|
||
| WORKDIR /prometheus | ||
| RUN mkdir -p /etc/prometheus /prometheus \ |
There was a problem hiding this comment.
With scratch this should be done in the first stage, as the image will not have mkdir chown etc.
|
I did not notice this. |
docker: add distroless container build option
This PR introduces support for building Prometheus container images based on distroless as an alternative to the current busybox-based images. The new distroless images contain only the statically linked Prometheus binaries, CA certificates, and timezone data, minimizing the attack surface and reducing vulnerability scanner noise.
Key changes:
Dockerfile.distrolessfor building minimal images usinggcr.io/distroless/static:nonrootas the base.common-docker-distrolesstarget intoMakefile.commonto build these images for all configured architectures.Rationale:
Which issue(s) does the PR fix:
Does this PR introduce a user-facing change?