Skip to content

Commit ceb6739

Browse files
authored
Document container creation steps (#12)
1 parent de16ba2 commit ceb6739

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

Dockerfile.checkpoint

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ARG JDK_NAME=zulu22.30.13-ca-crac-jdk22.0.1-linux_x64
2+
3+
FROM ubuntu:24.04 as builder
4+
ARG JDK_NAME
5+
6+
RUN apt-get update && apt-get install -y wget
7+
RUN wget -O crac-jdk.tar.gz https://cdn.azul.com/zulu/bin/$JDK_NAME.tar.gz
8+
RUN tar zxf ./crac-jdk.tar.gz -C /usr/share
9+
10+
# End of builder
11+
12+
FROM ubuntu:24.04
13+
ARG JDK_NAME
14+
ARG FAT_JAR=
15+
16+
ENV JDK_NAME=$JDK_NAME
17+
ENV JAVA_HOME=/usr/share/$JDK_NAME
18+
19+
COPY --from=builder /usr/share/${JDK_NAME} /usr/share/${JDK_NAME}
20+
RUN ln -s $JAVA_HOME/bin/java /bin/ && ln -s $JAVA_HOME/bin/jcmd /bin/
21+
ADD target/example-spring-boot*.jar /example-spring-boot.jar
22+
ENTRYPOINT [ "java", "-XX:CPUFeatures=generic", "-XX:CRaCCheckpointTo=/cr", "-jar", "/example-spring-boot.jar" ]
23+

Dockerfile.restore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM example-spring-boot-checkpoint
2+
ADD target/cr /cr
3+
ENTRYPOINT [ "java", "-XX:CRaCRestoreFrom=/cr" ]
4+
5+

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,38 @@ jcmd target/example-spring-boot-0.0.1-SNAPSHOT.jar JDK.checkpoint
3838
```
3939
$JAVA_HOME/bin/java -XX:CRaCRestoreFrom=cr
4040
```
41+
42+
## Preparing a container image
43+
44+
1. After building the project locally create an image to be checkpointed.
45+
```
46+
docker build -f Dockerfile.checkpoint -t example-spring-boot-checkpoint .
47+
```
48+
49+
2. Start a (detached) container that will be checkpointed. Note that we're mounting `target/cr` into the container.
50+
```
51+
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
52+
```
53+
54+
3. Validate that the container is up and running (here you could also perform any warm-up)
55+
```
56+
curl localhost:8080
57+
Greetings from Spring Boot!
58+
```
59+
60+
4. Checkpoint the running container
61+
```
62+
docker exec -it example-spring-boot-checkpoint jcmd example-spring-boot JDK.checkpoint
63+
```
64+
65+
5. Build another container image by adding the data from `target/cr` on top of the previous image and adjusting entrypoint:
66+
```
67+
docker build -f Dockerfile.restore -t example-spring-boot .
68+
```
69+
70+
6. (Optional) Start the application in the restored container and validate that it works
71+
```
72+
docker run -it --rm -p 8080:8080 example-spring-boot
73+
# In another terminal
74+
curl localhost:8080
75+
```

0 commit comments

Comments
 (0)