NashTech Blog

Table of Contents
two women looking at the code at laptop

Distroless images in Docker are a type of image which can be used as a slimmed in Linux distribution at runtime

of the application with the binary.

In the world of technology modernization the use of Distroless images in growing rapidly.

Uses of Distroless Images

There are some popular use cases of these images like:

  • Smaller size / lightweight: These images are much smaller than the standard Linux distributions, saving space on your Docker host and in the CI/CD pipelines.

  • Enhanced Security: These images used very few components which makes them less vulnerable to attack.

  • Saving cost: Since these images are smaller in size they use less memory to run which turns out to cost saving.

To run these images, some components are required:

Application binaries with the dependencies.

Operating System or containerized OS Platform.

Architecture

To use one can use Google-published images as a base image for the application.

Java Distroless Image

1. Create a Java file named TestDistrolessJava.java using the content:

package examples;
class HelloJava {
public static void main(String...args) throws Exception {
  System.out.println("Hello Java");
  Thread.sleep(2000);
  System.out.println("Hello Java - end");
 }
}

2. Create a Dockerfile with the content:

FROM openjdk:11-jdk-slim-bullseye AS build-env
COPY . /app/examples
WORKDIR /app
RUN ls /
RUN javac examples/*.java
RUN jar cfe main.jar examples.HelloJava examples/*.class
# FROM gcr.io/distroless/java11-debian11:latest
FROM gcr.io/distroless/java11-debian11:debug
COPY --from=build-env /app /app
WORKDIR /app
CMD ["main.jar"]

3. Run the command to create docker images:

docker build -t javaapp/hellojava:latest .

4. Run the image using the command:

docker run javaapp/hellojava:latest 

Conclusion

Many developers, architects and Devsecops consider distroless beneficial but many are in oppose of it. For each way (lightweight image and distroless image) are in similar size and security benefits. Follow for more content, click here.

Picture of Vikas Vashisth

Vikas Vashisth

Vikas Vashisth is working as a Sr.DevOps Engineer at Knoldus | Part of Nashtech with having more than multiple years of experience in the field of continuous integration and delivery, infrastructure automation, and containerization enables me to build scalable, reliable, and highly available environments. I am proficient in tools such as Docker, Kubernetes, Jenkins, Ansible, and Terraform, and have experience working with cloud platforms such as AWS, GCP, and Azure.

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

Scroll to Top