How to use CRaC with Spring Boot in a Docker Container

Transcript

Coordinated Restore at Checkpoint (CRaC) is an OpenJDK project designed to reduce the startup and warmup times of Java applications to just milliseconds. This tutorial demonstrates how to use CRaC with Spring Boot applications running in a Docker container. To follow along, you’ll need Docker (ensure it’s up and running) and a Spring Boot application (version 3.2 or later) since CRaC is supported in these versions. For this example, we’ll use the Spring Boot Petclinic application, which can be found on GitHub. Additionally, we’ll use the Liberica Runtime Container with CRaC support, available on Docker Hub and tagged with “CRaC.”
Open the application in your preferred IDE (e.g., IntelliJ IDEA). No modifications to the application code are necessary—simply add the CRaC project dependency to the pom.xml file (assuming you’re using Maven). You’ll also need a Dockerfile for containerizing the application. In the first stage of the Dockerfile, we use the Liberica Runtime Container based on Liberica JDK Lite 21 and Alpaquita Linux with musl support. This container supports CRaC (indicated by the CRaC tag). Here, we copy the project into the image and package it as a JAR file. In the second stage, we use the Liberica Runtime Container based on JRE to create a layered JAR (recommended by Spring). Finally, we assemble all the layers into a new image using Liberica JRE with CRaC support and define the ENTRYPOINT to create a snapshot when the application exits.

Next, we containerize the application using the docker build command and run it in a container. To create a checkpoint, enable the CAP_CHECKPOINT_RESTORE and SYS_PTRACE capabilities using the --cap-add flag. If your Linux kernel version is older than 5.9, you can use the --privileged flag, though it’s not recommended for production. Once checkpointed, the application logs its activity using the CRaC API. Create a fresh image with a checkpoint using the docker commit command and update the ENTRYPOINT to restore the application from the snapshot. Remove the previous container (docker rm -f) and start the application from the snapshot, specifying the port and required capabilities. The application will start in milliseconds. You can launch multiple Petclinic instances in separate containers by specifying unique ports and container names. To verify the application, open it in a browser—it should run without issues. For copy-and-paste code snippets, refer to the dedicated guide linked in the description box of the video.

Summary

CRaC (Coordinated Restore at Checkpoint) is an OpenJDK project designed to significantly reduce startup and warmup times of Java applications to milliseconds. This tutorial demonstrates using CRaC with a Spring Boot application running in a Docker container, specifically the Spring Boot Petclinic app (version 3.2 or later).

About Catherine

Java developer passionate about Spring Boot. Writer. Developer Advocate at BellSoft

Social Media

Videos
card image
Jun 18, 2025
Java DTO Guide: Fix Your API Design with One Simple Pattern

This tutorial shows how to use the Data Transfer Object (DTO) pattern to transfer data between application layers. We use Java records to reduce boilerplate code and the MapStruct library that simplifies Java bean mapping.

Videos
card image
Jun 13, 2025
Downgraded Java to JDK 1.1 After 30 Years… (part 1)

How should we change Java 23 code for it to run on Java 1.1? We go line by line, removing modern features like records, sealed classes, switch expressions, var, and more. Each step reveals what breaks, how to rewrite it, and what you lose in the process. If you've ever wondered how far modern Java has drifted from its roots - this is your deep dive into that gap. This is Part 1 of the Java Downgrade Challenge, where we descend version by version until we reach Java 8. Subscribe to our channel to find out how we go even deeper - all the way down to Java 1.1. Stay tuned!

Further watching

Videos
card image
Jul 15, 2025
Java Downgrade Challenge: From JDK 8 to 1.1 (Part 2)

In Part 2 of the Java Downgrade Challenge, we continue our journey — now from Java 8 all the way to Java 1.1. No streams, no lambdas, no generics, no collections — and at one point, we even boot up Windows 98. If you thought Part 1 was painful, this one unwinds Java history line by line. By the end, the familiar Java from today will be almost gone.

Videos
card image
Jun 27, 2025
5x Smaller Java Docker Images — 2025 Optimization Guide

In this video, I’ll show you how to make your Java Docker images 5 TIMES SMALLER. You’ll see the full process, from a heavy 587MB container to a lean 116MB image, ready for production.

Videos
card image
Jun 23, 2025
How to install Liberica Native Image Kit on Windows PC

Liberica Native Image Kit is a multilingual GraalVM-based set of utilities for creating native images. This guide will help you to install it on Windows PC.