"Distroless" Container Images.
"Distroless" images contain only your application and its runtime dependencies.
They do not contain package managers, shells or any other programs you would expect to find in a standard Linux distribution.
For more information, see this talk (video).
Since March 2023, Distroless images use oci manifests, if you see errors referencing application/vnd.oci.image.manifest.v1+json
or application/vnd.oci.image.index.v1+json
, update your container tooling (docker, jib, etc) to latest.
Why should I use distroless images?
Restricting what's in your runtime container to precisely what's necessary for your app is a best practice employed by Google
and other tech giants that have used containers in production for many years.
It improves the signal to noise of scanners (e.g. CVE) and reduces the burden of establishing provenance to just what you need.
Distroless images are very small.
The smallest distroless image, gcr.io/distroless/static-debian12
, is around 2 MiB.
That's about 50% of the size of alpine
(~5 MiB), and less than 2% of the size of debian
(124 MiB).
How do I use distroless images?
These images are built using bazel, but they can also be used through other Docker image build tooling.
What images are available?
The following images are currently published and updated by the distroless project (see SUPPORT_POLICY for support timelines)
Debian 12
These images refer to image indexes with references to all supported architectures. Architecture specific images can be directly referenced using an additional architecture suffix on the tag, like gcr.io/distroless/static-debian12:latest-amd64
Any other tags are considered deprecated and are no longer updated
How do I verify distroless images?
All distroless images are signed by cosign with emphemeral keys (keyless) -- this is the only supported mechanism starting November 2023.
We recommend verifying any distroless image you use before building your image. You can verify the keyless signature of any distroless image with:
Entrypoints
Note that distroless images by default do not contain a shell.
That means the Dockerfile ENTRYPOINT
command, when defined, must be specified in vector
form, to avoid the container runtime prefixing with a shell.
This works:
But this does not work:
For the same reasons, if the entrypoint is set to the empty vector, the CMD command should be specified in vector
form (see examples below).
Note that by default static, base and cc images have the empty vector entrypoint. Images with an included language runtime have a language specific default (see: java, nodejs, python3).
Docker
Docker multi-stage builds make using distroless images easy.
Follow these steps to get started:
-
Pick the right base image for your application stack.
-
Write a multi-stage docker file.
Note: This requires Docker 17.05 or higher.The basic idea is that you'll have one stage to build your application artifacts, and insert them into your runtime distroless image.
If you'd like to learn more, please see the documentation on multi-stage builds.
Examples with Docker
Here's a quick example for go:
You can find other examples here:
To run any example, go to the directory for the language and run
To run the Node.js Express app node-express and expose the container's ports:
This should expose the Express application to your localhost:3000
Bazel
For full documentation on how to use bazel to generate Container images, see the bazel-contrib/rules_oci repository.
For documentation and example on how to use the go-based debian package manager (current) to generate bazel config, see ./debian_package_manager
For documentation and examples on how to use the bazel package manager rules (not used in this repo), see ./package_manager
Examples can be found in this repository in the examples directory.
Examples with Bazel
We have some examples on how to run some common application stacks in the /examples directory.
See here for:
See here for examples on how to complete some common tasks in your image:
See here for more information on how these images are built and released.
Base Operating System
Distroless images are based on Debian 12 (bookworm). Images are explicitly tagged with Debian version suffixes (e.g. -debian12
). Specifying an image without the distribution will currently select -debian12
images, but that will change in the future to a newer version of Debian. It can be useful to reference the distribution explicitly, to prevent breaking builds when the next Debian version is released.
Operating System Updates for Security Fixes and CVEs
Distroless tracks the upstream Debian releases, using Github actions to automatically generate a pull request when there are updates.
Debug Images
Distroless images are minimal and lack shell access. The :debug
image set for each language provides a busybox shell to enter.
For example:
edit the Dockerfile
to change the final image to :debug
:
then build and launch with an shell entrypoint:
Note: If the image you are using already has a tag, for example
gcr.io/distroless/java17-debian12:nonroot
, use the tagdebug-
instead, for examplegcr.io/distroless/java17-debian12:debug-nonroot
.
Note: ldd is not installed in the base image as it's a shell script, you can copy it in or download it.
Who uses Distroless?
- Kubernetes, since v1.15
- Knative
- Tekton
- Teleport
If your project uses Distroless, send a PR to add your project here!
Community Discussion
No reviews found!
No comments found for this product. Be the first to comment!