I want to create a docker image that runs on a Java Service with OpenJ9's Class Data Sharing feature to improve startup performance. I want to create the Class Cache while building the image using a multi stage docker build. I saw a few mentions of pre warming a docker image like this online
https://github.com/barecode/adopt-openj9-spring-boot/blob/master/Dockerfile.openj9.warmed
however, i'm not able to recreate it here is my Dockerfile
FROM adoptopenjdk/openjdk11-openj9:alpine as base
ADD libs/ /libs
ADD service.jar /service.jar
RUN mkdir /hi
WORKDIR /hi
RUN ls /
RUN java -Xshareclasses:name=mycache -Xshareclasses:cacheDir=/hi -Xshareclasses -jar /usr/share/app/service.jar &
RUN sleep 5
RUN ls -la /hi
FROM adoptopenjdk/openjdk11-openj9:alpine-jre
COPY --from=base libs/ /usr/share/app/libs
COPY --from=base service.jar /usr/share/app/service.jar
RUN /bin/sh -c 'ps aux | grep java | grep service | awk '{print $2}' | xargs kill -1'
#RUN java -Xshareclasses:listAllCaches
ENTRYPOINT ["java","-jar", "-Xshareclasses" , "-Xtune:virtualized", "-XX:+UseContainerSupport", "/usr/share/app/service.jar"]
my problem is that when I'm running
RUN java -Xshareclasses:name=mycache -Xshareclasses:cacheDir=/hi -Xshareclasses -jar /usr/share/app/service.jar &
and then expecting the cache file to be saved on /hi, the file isn't there.
any help will be appreciated. Thanks.
OpenJ9 only reads the last
-Xshareclasses
option provided. This makes it easy to replace previous options in the commandline when developing / debugging as in some environments, it's hard to modify the existing commandline args.Change the command to:
and the cache will be created in the
/hi
directory.For example: