Skip to content

Commit

Permalink
Document container creation steps (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvansa authored May 30, 2024
1 parent de16ba2 commit ceb6739
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
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
```

0 comments on commit ceb6739

Please sign in to comment.