The best way to run Spring Boot services!

Do you want to

  • Reduce the size of your apps?
  • Save up to 40% of RAM?
  • Enhance security of you Cloud environment?

Just install Paketo, execute 2 strings of code, and enjoy running your app in a better environment!

How to use Alpaquita buildpacks with Spring Boot

The easiest way to start enjoying the Alpaquita technology is by using the Packeto Buildpack.
If you utilize Maven or Gradle to build your projects, you can create an Alpaquita image with a simple addition to your configuration that switches the standard buildpack to Alpaquita buildpack.

To prove the advantages of Alpaquita containers vs the default way to run Java applications, we ran multiple tests that you can replicate.

Install the pack utility. Check this guide for the instructions.

Edit pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <image>
		    <name>paketo-maven</name>
                    <builder>bellsoft/buildpacks.builder:musl</builder>
                </image>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

Build the image with Maven: mvn spring-boot:build-image

Launch the container: docker run paketo-maven

Install the pack utility. Check this guide for the instructions.

Edit pom.xml:

plugins {
	id 'java'
	id 'org.springframework.boot' version '3.0.6'
	id 'io.spring.dependency-management' version '1.1.0'
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

bootBuildImage {
	imageName = "paketo-gradle"
	builder = "bellsoft/buildpacks.builder:musl"
}

Build the image with Maven: gradle bootBuildImage

Launch the container: docker run paketo-gradle

Install the pack utility. Check this guide for the instructions.

Edit pom.xml:

plugins {
	java
	id("org.springframework.boot") version "3.0.6"
	id("io.spring.dependency-management") version "1.1.0"
}

dependencies {
	implementation("org.springframework.boot:spring-boot-starter")
	testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.bootBuildImage {
	imageName.set("paketo-gradle-kotlin")
	builder.set("bellsoft/buildpacks.builder:musl")
}

Build the image with Maven: gradle bootBuildImage

Launch the container: docker run paketo-gradle-kotlin

If you don't have a project ready for testing, visit Spring Initilizr and create it there. It will contain all the dependencies, so all you will have to do is add the configuration for bootBuildImage, or run pack with required parameters.

In this example, we use Spring Petclinic as the application we put into the buildpack. You can use your app instead when you are ready.

The following code will return a copy of Petclinic from the most recent commit at the time of writing of this tutorial:

curl -L https://github.com/spring-projects/spring-petclinic/archive/a5cbb8505a1df3c348c06607933a07fc8c87c222.zip --output spring-petclinic-main.zip

unzip ./spring-petclinic-main.zip

mv ./spring-petclinic-a5cbb8505a1df3c348c06607933a07fc8c87c222 ./spring-petclinic-main

cd ./spring-petclinic-main && ./mvnw package

After you finish building your container, you can check out its size, the version of Alpaquita inside, and the contents of the package. See for yourself how Packeto buildpacks creates the production-ready Docker images with Alpaquita inside!

This is the list of useful Docker commands that may help.

  • To check how much disk space the image takes, run

    docker image ls demo-app

    The result should be similar to the output below:

    REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
    demo-app     latest    24ac5ac02b2a   43 years ago   152MB
  • To find out the OS version in package, run

    docker run --rm -it --entrypoint /bin/cat demo-app /etc/os-release

    For our image, the result should be:

    NAME="BellSoft Alpaquita Linux Stream"
    ID=alpaquita
    ID_LIKE=alpine
    VERSION_ID=23
    PRETTY_NAME="BellSoft Alpaquita Linux Stream 23 (musl)"
    HOME_URL="https://bell-sw.com/"
    BUG_REPORT_URL="https://bell-sw.com/support/"
    LIBC_TYPE=musl
    
  • Last but not least, let’s see what is inside the container built by Paketo without unpacking it. Run the following command (which is built into the Paketo):

    pack inspect demo-app

    If you used the Petclinic app, the result will likely be the following:

    Inspecting image: demo-app
    
    REMOTE:
    (not present)
    
    LOCAL:
    
    Stack: io.buildpacks.stacks.alpaquita-musl
    
    Base Image:
      Reference: 116beca369efbba0a9dfff7361b7ce7c302cac684904ddc365e7d6ba82505f58
      Top Layer: sha256:7caddaa60b9c1ca8f0dfa5882f96239493ef54e94e5e8c47ddf84745186eff35
    
    Run Images:
      bellsoft/buildpacks.alpaquita-run:musl
    
    Buildpacks:
      ID                                      VERSION        HOMEPAGE
      bellsoft/buildpacks/liberica            1.0.0          https://github.com/bell-sw/buildpacks/liberica
      paketo-buildpacks/syft                  1.26.0         https://github.com/paketo-buildpacks/syft
      paketo-buildpacks/gradle                6.11.0         https://github.com/paketo-buildpacks/gradle
      paketo-buildpacks/maven                 6.13.0         https://github.com/paketo-buildpacks/maven
      paketo-buildpacks/executable-jar        6.6.1          https://github.com/paketo-buildpacks/executable-jar
      paketo-buildpacks/spring-boot           5.23.0         https://github.com/paketo-buildpacks/spring-boot
    
    Processes:
      TYPE                  SHELL        COMMAND        ARGS                                              WORK DIR
      web (default)                      java           -jar /workspace/spring-petclinic-3.0.0.jar        /workspace
      executable-jar                     java           -jar /workspace/spring-petclinic-3.0.0.jar        /workspace
      task                               java           -jar /workspace/spring-petclinic-3.0.0.jar        /workspace
    

What makes BellSoft’s Containers for Spring efficient?

How does Alpaquita help?

How does Alpaquita help?

Alpaquita Linux is the OS fine-tuned to run Java applications with multiple advantages that make it the natural choice for containers with Spring Boot services:

  • Minimal memory footprint with base image size of 3.22 MB;
  • Better performance thanks to kernel optimizations, memory management, optimized mallocs;
  • Enhanced flexibility with glibc and both standard and optimized musl available.
Why use Liberica JDK Lite?

Why use Liberica JDK Lite?

Liberica JDK Lite is the most performant and lightweight build of BellSoft’s runtime. It works best in containers because it is:

  • Ideal for cloud with its minimal size;
  • Has lower infrastructure costs thanks to optimized memory consumption;
  • Trusted by VMWare. The standard build of Liberica JDK is used in Spring Boot by default.

Cloud native
containers

Why choose the container with Alpaquita Linux and Liberica JDK Lite for Spring applications?
  • It saves you money thanks to its tiny size, great performance, and stability;
  • It is easy to use. Just follow our tutorial below on this page;
  • No migration effort, Switching to BellSoft’s container is easy;
  • It is free. You can develop, test, and deploy BellSoft’s containers for free and later select to purchase one of our flexible support plans.
  • It is secure with custom build options, kernel hardening, process isolation, and regular security updates.

Benchmarks: Alpaquita + Liberica Lite vs OpenJDK + DockerHub

To prove the advantages of Alpaquita containers vs the default way to run Java applications, we ran multiple tests that you can replicate.

The following tests measure the RAM consumed by the same app launched within two images:

Note that while the “official” image is not supported anymore, it can be used as the “average” OpenJDK implementation and the reference point. You can use other distros in tests, for example, “temurin”, which is supported. See the list in the “kits” file.

Step 1: Download the scripts

First, download measurement scripts (tested on Mac, Linux, and Windows) from the GitHub repository.

Step 2: Refresh Docker and buildx

You will need Docker to enable the buildx command, so install it if necessary. Next, check the version of the buildx command by launching docker buildx version. The version we needed was v0.8 or higher, the scripts were tested on v0.10.3, the latest at the moment of testing. If your buildx version is too low, install the new one.

Step 3: Create builder

For buildx to run, you need to configure it by running create_builder or create_builder.bat for Windows.

Step 4: Build the application for testing

Now, it is time to choose what app you are going to test, your own or demo (in our case, Spring Petclinic).
If you decide to utilize Petclinic, run the ./bake script (Mac, Linux), or bake.bat (Windows).
Wait some time and check the results in the target folder.
In case you use your app, build the JAR file and then put it into the target folder of the project.
The name of the file must be “app.jar”.
Run the ./bake custom (Mac, Linux) or bake.bat custom (Windows).

Step 5: Run the tests

In case you use Petclinic, just run the ./test script with no parameters.
If you use your own app, run the same script with a single argument, which is the address where your app listens for connections (like ./test http://localhost:9090/endpoint).

Step 6: Wait for a bit

The script launches several processes:

  • Downloading several necessary artifacts from Maven Central (for Petclinic);
  • Java application building (for Petclinic);
  • Loading and building of wrk2 and psrecord (which is a native C++ code and will take a lot of time);
  • Loading and building the Python modules for the traffic analysis (pandas, numpy);
  • Running the tests.

You may need to wait for a while.

Step 7: Analyze the results

To check the image size, run the docker images command and look for two images,petclinic-alpaquita and petclinic-official.

Retrieve the results from the logs folder. Other than the logs that display the RAM load results, there are two more important files: frequency.png и median.png.
median.png is the graph that shows the median values of RAM consumption for both images. The frequency.png graph displays the frequency distribution of RAM consumption by images. The X-axis represents the RAM consumption, the Y-axis shows how much time the application managed to hold the corresponding level of RAM consumption. The second graph could be more important for analysis but is more difficult to interpret.petclinic-alpaquita and petclinic-official.

Step 8: Share your results!

We hope you will share the results of your testing with the world! Please mention us (https://twitter.com/bellsoftware) in your reply so we can answer your questions and see your results.

These are our results. As you can see, Alpaquita container shows the significantly better results compared to the standard OpenJDK + Docker:

Image size

Image size

RAM consumption

RAM consumption

Start using Alpaquita Linux today!

These are all the links and additional info you may need to try and use Alpaquita Linux with your Spring Boot applications:

Alpaquita Cloud Native Platform

Get all the benefits of Alpaquita buildpacks with native image technology integrated for even lower size and better startup time, and commercial support.

Learn more
media

Discover Alpaquita Linux

Learn more about a full-featured operating system optimized for Java.

Learn more

Learn to dockerize Spring boot apps

See all the steps of dockerizing a Spring Boot app using a microcontainer with Liberica Lite and Alpaquita Linux.

Learn more

Spring Boot 3 with GraalVM Native image

Look into the configuration of Spring Boot apps for native image technology and avoiding migration issues

Learn more

More on Spring Boot and GraalVM Native image

Find out the intricacies associated with Spring Boot Native Image development

Learn more

Get guidance on migrating to Alpaquita Cloud Native Platform

Speak with an expert to see which solution will serve your business the best

* This field is required