Home > front end >  Spring Boot app crashing in Docker container (but not at cmd line)
Spring Boot app crashing in Docker container (but not at cmd line)

Time:01-24

I have a small Spring Boot rest service that runs fine with:

java -jar myapp.jar

...but when I deploy in a docker container, it crashes the container when I access the service with curl:

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x00007f052205991a, pid=1, tid=40

JRE version: OpenJDK Runtime Environment Temurin-19.0.1 10 (19.0.1 10) (build 19.0.1 10) Java VM: OpenJDK 64-Bit Server VM Temurin-19.0.1 10 (19.0.1 10, mixed mode, sharing, tiered, compressed oops, compressed class pt> Problematic frame: V [libjvm.so 0xe2f91a] JVM_handle_linux_signal 0x13a

The Dockerfile:

FROM amd64/eclipse-temurin:19.0.1_10-jre-alpine
VOLUME /opt/galleries
RUN mkdir -p /opt/rest.galleries/logs/
ARG JAR_FILE
ADD ${JAR_FILE} /opt/rest.galleries/app.jar
EXPOSE 8000
ENTRYPOINT ["java","-jar","/opt/rest.galleries/app.jar"]

Creating the container from the image:

docker run -p 8000:8000 -v /opt/galleries:/opt/galleries --memory="1g" --memory-swap="2g" -t craigfoote/rest.galleries:latest &

I am using these libraries to read webp and jpg images.:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-imaging</artifactId>
    <version>1.0-alpha3</version>
</dependency>
<dependency>
    <groupId>org.sejda.imageio</groupId>
    <artifactId>webp-imageio</artifactId>
    <version>0.1.6</version>
</dependency>

I'm building to a image via:

<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.4.13</version>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <goal>build</goal>
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <repository>${project.artifactId}</repository>
        <tag>${project.version}</tag>
        <buildArgs>
            <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
        </buildArgs>
    </configuration>
</plugin>

The point at which it crashes is a call to:

ImageIO.read(file); // where file is a 238kB webp image

Since it works at cmd line, I assume the code operation itself is not the problem but it may be causing it, perhaps a memory issue? I tried modifying the docker run command to increase ram and swap but it didn't help:

docker run -p 8000:8000 -v /opt/galleries:/opt/galleries --memory="4g" --memory-swap="8g" -t craigfoote/rest.galleries:latest &

When the crash occurs, the console states that a hs_err_pid1.log file was written but I can't find it.

Any ideas anyone?

CodePudding user response:

It appears that the base image, amd64/eclipse-temurin:19.0.1_10-jre-alpine, uses a different libc than org.sejda.imageio:webp-imageio. I changed to ubuntu base and installed openjdk-19 and everything works now. My Dockerfile:

FROM ubuntu:latest
RUN apt update && \
    apt install -y openjdk-19-jdk ca-certificates-java && \
    apt clean && \
    update-ca-certificates -f
ENV JAVA_HOME /usr/lib/jvm/java-19-openjdk-amd64/
RUN export JAVA_HOME
VOLUME /opt/galleries
RUN mkdir -p /opt/rest.galleries/logs/
ARG JAR_FILE
ADD ${JAR_FILE} /opt/rest.galleries/app.jar
EXPOSE 8000
ENTRYPOINT ["java","-jar","/opt/rest.galleries/app.jar"]
  • Related