Skip to content

Document container creation steps #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Dockerfile.checkpoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ARG JDK_NAME=zulu22.30.13-ca-crac-jdk22.0.1-linux_x64

FROM ubuntu:24.04 as builder
ARG JDK_NAME

RUN apt-get update && apt-get install -y wget
RUN wget -O crac-jdk.tar.gz https://cdn.azul.com/zulu/bin/$JDK_NAME.tar.gz
RUN tar zxf ./crac-jdk.tar.gz -C /usr/share

# End of builder

FROM ubuntu:24.04
ARG JDK_NAME
ARG FAT_JAR=

ENV JDK_NAME=$JDK_NAME
ENV JAVA_HOME=/usr/share/$JDK_NAME

COPY --from=builder /usr/share/${JDK_NAME} /usr/share/${JDK_NAME}
RUN ln -s $JAVA_HOME/bin/java /bin/ && ln -s $JAVA_HOME/bin/jcmd /bin/
ADD target/example-spring-boot*.jar /example-spring-boot.jar
ENTRYPOINT [ "java", "-XX:CPUFeatures=generic", "-XX:CRaCCheckpointTo=/cr", "-jar", "/example-spring-boot.jar" ]

5 changes: 5 additions & 0 deletions Dockerfile.restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM example-spring-boot-checkpoint
ADD target/cr /cr
ENTRYPOINT [ "java", "-XX:CRaCRestoreFrom=/cr" ]


35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,38 @@ jcmd target/example-spring-boot-0.0.1-SNAPSHOT.jar JDK.checkpoint
```
$JAVA_HOME/bin/java -XX:CRaCRestoreFrom=cr
```

## Preparing a container image

1. After building the project locally create an image to be checkpointed.
```
docker build -f Dockerfile.checkpoint -t example-spring-boot-checkpoint .
```

2. Start a (detached) container that will be checkpointed. Note that we're mounting `target/cr` into the container.
```
docker run -d --rm -v $(pwd)/target/cr:/cr --cap-add=CHECKPOINT_RESTORE --cap-add=SYS_PTRACE -p 8080:8080 --name example-spring-boot-checkpoint example-spring-boot-checkpoint
```

3. Validate that the container is up and running (here you could also perform any warm-up)
```
curl localhost:8080
Greetings from Spring Boot!
```

4. Checkpoint the running container
```
docker exec -it example-spring-boot-checkpoint jcmd example-spring-boot JDK.checkpoint
```

5. Build another container image by adding the data from `target/cr` on top of the previous image and adjusting entrypoint:
```
docker build -f Dockerfile.restore -t example-spring-boot .
```

6. (Optional) Start the application in the restored container and validate that it works
```
docker run -it --rm -p 8080:8080 example-spring-boot
# In another terminal
curl localhost:8080
```