Distroless images
Distroless images are minimal docker images that contain only your application and its runtime dependencies. They do not contain os, package managers, shells, or other tools that are typically included in a Linux distribution. This makes distroless images more secure and lightweight than traditional images.
The name "distroless" comes from the fact that these images are "less" than a full Linux distribution. They are designed to be used as base images for containerized applications, providing a clean and secure environment for running your code.
There is a misconception that distroless images are not suitable for debugging or troubleshooting because they do not contain debugging tools or shells. However, you can still debug a distroless image using ephemeral containers in Kubernetes or other debugging techniques and this has been explained below.
Distroless images and slim images are similar in that they both aim to reduce the size of the container image by removing unnecessary components. However, slim images still contain an operating system and package manager, while distroless images do not.
Building distroless image¶
Below are few examples of how you can build a distroless image for different types of applications:
Dockerfile | |
---|---|
Reference
You can check the above example in the paul58914080 / distroless-tryout
Reference
You can check the above example in the paul58914080 / distroless-tryout
Adding certificates to a distroless image¶
You can modify the above docker file to add certificates to the distroless image. Here's an example of how to add certificates to a distroless image:
Debugging a distroless image¶
Debugging a distroless image can be challenging because it does not contain debugging tools like shells or package managers. However, you can use ephemeral containers in Kubernetes to debug a running distroless image. Ephemeral containers are temporary containers that can be added to a running pod for debugging purposes. They do not persist after the pod is restarted and do not affect the existing containers in the pod.
Debugging a distroless image using ephemeral containers¶
To debug a distroless image using an ephemeral container, you can use the following command:
The above command adds an ephemeral container to a running pod and allows you to execute commands in the target container for debugging purposes. Replace <pod-name>
with the name of the running pod and <container-name>
with the name of the target container within the pod.
Debugging a distroless image using share-processes¶
You can also do it via share-processes:
This will allow you to share the processes of the target container and debug it using the busybox container.