How to solve Gradle docker image freezing on Raspberry Pi with warning about monotonic clock?

1.1k Views Asked by At

I am trying to set up a Docker container that builds and runs a small application. This is my Dockerfile:

#####################
# build the jar
#####################

FROM gradle:jdk11 as builder
COPY --chown=gradle:gradle application /application
WORKDIR /application
RUN gradle build

#####################
# run the app
#####################

# Use this on a non-arm machine
# FROM openjdk:11

# Use this on an arm machine, such as a raspberry pi
FROM arm32v7/adoptopenjdk:11

EXPOSE 8080
COPY --from=builder /application/build/libs/myjar.jar .
WORKDIR /
CMD java -jar ./myjar.jar

docker build -t myimage . works without problems on my personal machine (a Macbook Pro). If I try to build the image on a Raspberry Pi 4B (which is ultimately the goal), it hangs at the RUN gradle build step and never completes.

This is my terminal output:

pi@raspberrypi:~/development/my_test $ docker build -t test . 
Sending build context to Docker daemon  15.92MB
Step 1/9 : FROM gradle:jdk11 as builder
 ---> 0924090a3770
Step 2/9 : COPY --chown=gradle:gradle application /application
 ---> Using cache
 ---> b702fc76b9cb
Step 3/9 : WORKDIR /application
 ---> Using cache
 ---> dbc2aac75c7c
Step 4/9 : RUN gradle --no-daemon  build
 ---> Running in faec45c6cf01
OpenJDK Server VM warning: No monotonic clock was available - timed services may be adversely affected if the time-of-day clock changes

And that's it. Nothing further happens.

At first, I had ignored the OpenJDK warning since I had seen it with other images and had no problems running them. After every other option failed, I started to suspect it might be the culprit. How can this be resolved?

2

There are 2 best solutions below

0
On BEST ANSWER

I found the solution: As it turns out, the missing monotonic clock can lead to unpredictable behaviour with java. Some applications run, some have errors, some don't start. Turns out, the missing clock issue can be fixed by installing libseccomp 2.4.2 or higher, which unfortunately does not get served by apt on the pi. So it seems like the only way currently is a manual install as described here, from the source page here. I did this and the error went away, Gradle started to run, build my app and print the proper output to the terminal.

0
On

I successfully tested below solution for the Raspberry Pi 4 (Raspbian 10 buster) for jdk 16 and jdk 17:

#Add dep Key
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138
#Add dep 
sudo echo 'deb http://httpredir.debian.org/debian buster-backports main contrib non-free' | sudo tee -a /etc/apt/sources.list.d/debian-backports.list
#Update and Install
sudo apt update
sudo apt install libseccomp2 -t buster-backports

Source: https://community.openhab.org/t/docker-openhab-3-2-0-snapshot-stuck-at-unhealthy-with-openjdk-client-vm-warning-no-monotonic-clock-was-available/128865/7