Spring Boot app crashing in Docker container (but not at cmd line) - spring-boot

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?

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

Kernel-slim UBI docker image not working with springBootUtility

Team, Is it possible to use springBootUtility with OpenLiberty kernel-slim UBI images (e.g. - kernel-slim-java8-openj9-ubi) ?
https://openliberty.io/docs/21.0.0.7/reference/command/springbootUtility-thin.html
Because, it's giving an error as
Step 3/11 : RUN springBootUtility thin --sourceAppPath=/staging/fat-order-0.0.1-SNAPSHOT.jar --targetThinAppPath=/staging/thin-order-0.0.1-SNAPSHOT.jar --targetLibCachePath=/staging/lib.index.cache
---> Running in 3023c669c4d7
/bin/sh: springBootUtility: command not found
The springBootUtility is only working with OpenLiberty full UBI images
The kernel-slim image does not appear to have that command at all. Compare kernel-slim:
bash-5.1$ docker run --rm -it openliberty/open-liberty:kernel-slim-java8-openj9-ubi ls /opt/ol/wlp/bin
auditUtility binaryLog.bat productInfo securityUtility.bat serverSchemaGen
auditUtility.bat featureUtility productInfo.bat server serverSchemaGen.bat
binaryLog featureUtility.bat securityUtility server.bat tools
To full:
bash-5.1$ docker run --rm -it openliberty/open-liberty:full-java8-openj9-ubi ls /opt/ol/wlp/bin
auditUtility binaryLog.bat featureUtility pluginUtility securityUtility.bat springBootUtility
auditUtility.bat client featureUtility.bat pluginUtility.bat server springBootUtility.bat
batchManager client.bat jaxb productInfo server.bat tools
batchManager.bat ddlGen jaxrs productInfo.bat serverSchemaGen
binaryLog ddlGen.bat jaxws securityUtility serverSchemaGen.bat
There appears to be a hole in the documentation, since nothing indicates you need to do this, but you need to install the springBoot feature into Open Liberty before the command will be added. Copy your server.xml with spring boot specified into the image, then run features.sh:
COPY --chown=1001:0 server.xml /config/
RUN features.sh
After that, springBootUtility will be placed in the /opt/ol/wlp/bin dir and should be on the path as well for further Dockerfile directives to use.

Exit from shell script after execution via maven

I am executing below shell script (my.sh) via maven as shown below.
#!/bin/sh
oc login "https://server-name:8443" --insecure-skip-tls-verify--
echo "Enter userid password"
UN="username"
PWD="password"
-u $UN -p $PWD
oc project dev1
oc port-forward image-name 1521:1521 && exit
POM
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>my-exec</id>
<phase>initialize</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>sh</executable>
<arguments>
<argument>-c</argument>
<argument>${project-home}/resources/my.sh</argument>
</arguments>
</configuration>
</plugin>
But the problem is when run mvn command ( mvn spring-boot:run -Dspring-boot.run.profiles=it)
then terminal stops at Forwarding from 127.0.0.1:1521 -> 1521 and stuck there without move forward.
After changing the last line as below it worked.
nohup oc port-forward image-name 1521:1521 > /dev/null 2>&1 </dev/null &
echo
the >/dev/null pipes the parent log output to a void directory
it's a workaround for starting a background process easily
nohup - disconnects the inputs and outputs of the background sub-process being launched from the parent process and tells the sub-process not to respond to HUP (hangup) signal

Jib-Maven-plugin with Jenkins scripted pipeline: how to log in to private docker registry?

Regarding this problem, I updated my JHipster-Application with scripted Jenkins pipeline and have now in Jenkinsfile (partly following these hints):
[...]
def dockerImage
withEnv(["DOCKER_CREDS=credentials('myregistry-login')"]) {
stage('publish docker') {
sh "./mvnw -X -ntp jib:build"
}
}
with Jenkins global credentials myregistry-login saved in my Jenkins-Server to my own docker registry v2 docker-container https://myregistry.mydomain.com (domain changed for security reasons). I can successfully do a $ docker login myregistry.mydomain.com (as well as docker login https://myregistry.mydomain.com as well as docker login myregistry.mydomain.com:443) from local bash with the user and password stored in myregistry-login.
In pom.xml (following these hints as well as this, this and this):
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<to>
<image>myregistry.mydomain.com:443/username/imagename</image>
<tags>
<tag>${maven.build.timestamp}</tag>
<tag>latest</tag>
</tags>
<auth>
<username>${env.DOCKER_CREDS_USR}</username>
<password>${env.DOCKER_CREDS_PSW}</password>
</auth>
</to>
<container>
<jvmFlags>
<jvmFlag>-Xms512m</jvmFlag>
<jvmFlag>-Xmx1G</jvmFlag>
<jvmFlag>-Xdebug</jvmFlag>
</jvmFlags>
<mainClass>de.myproject_name.MyApp</mainClass>
</container>
</configuration>
</plugin>
where username, imagename and de.myproject_name.MyApp are placeholders here.
Unfortunately I get
[DEBUG] TIMING Retrieving registry credentials for myregistry.mydomain.com:443
[DEBUG] No credentials could be retrieved for registry myregistry.mydomain.com:443
[...]
[ERROR] I/O error for image [myregistry.mydomain.com:443/username/imagename]:
[ERROR] Connect to myregistry.mydomain.com:443 [myregistry.mydomain.com/xxx.xxx.xxx.xxx] failed: Connection refused (Connection refused)
[DEBUG] TIMED Authenticating push to myregistry.mydomain.com:443 : 460.0 ms
[DEBUG] TIMED Building and pushing image : 514.0 ms
[ERROR] I/O error for image [registry-1.docker.io/library/adoptopenjdk]:
[ERROR] Socket closed
So the withEnv isn't forwarded to Maven and/or the jib-maven-plugin is not reading the <auth>-Tag, right? What am I still doing wrong?
And why is there an I/O error to registry-1.docker.io?
Finally I've got it working.
In Jenkinsfile I edit the JHipster generated code to:
def dockerImage
stage('publish docker') {
withCredentials([usernamePassword(credentialsId: 'myregistry-login', passwordVariable: 'DOCKER_REGISTRY_PWD', usernameVariable: 'DOCKER_REGISTRY_USER')]) {
sh "./mvnw -ntp jib:build" }
}
In pom.xml I put the jib-maven-plugin configuration:
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<from>
<image>adoptopenjdk:11-jre-hotspot</image>
</from>
<to>
<auth>
<username>${DOCKER_REGISTRY_USER}</username>
<password>${DOCKER_REGISTRY_PWD}</password>
</auth>
<image>myregistry.mydomain.com/myuser/my_image</image>
<tags>
<tag>${maven.build.timestamp}</tag>
<tag>latest</tag>
</tags>
</to>
<container>
<jvmFlags>
<jvmFlag>-Xms512m</jvmFlag>
<jvmFlag>-Xmx1G</jvmFlag>
<jvmFlag>-Xdebug</jvmFlag>
</jvmFlags>
<mainClass>com.mypackage.MyApp</mainClass>
<entrypoint>
<shell>bash</shell>
<option>-c</option>
<arg>chmod +x /entrypoint.sh && sync && /entrypoint.sh</arg>
</entrypoint>
<ports>
<port>8080</port>
</ports>
<environment>
<SPRING_OUTPUT_ANSI_ENABLED>ALWAYS</SPRING_OUTPUT_ANSI_ENABLED>
<JHIPSTER_SLEEP>0</JHIPSTER_SLEEP>
</environment>
<creationTime>USE_CURRENT_TIMESTAMP</creationTime>
</container>
</configuration>
</plugin>
In my remote server setup my own docker registry v2 is running as a docker-container published via nginx-proxy with letsencrypt-nginx-proxy-companion. On the same custom network bridge runs my own jenkins server as another docker-container.
Some tests showed me that the container-name of the docker registry can not be named with the public DNS name of the registry (e.g. 'myregistry.mydomain.com' as container name). The jenkins docker-container gets the embedded docker dns server into resolv.conf, and docker will resolve the container-names of containers in the same network to the internal bridge-network IPs of these containers (only in case of custom docker networks).
I guess jib has to connect via ssl to push the docker image to the docker registry container and ssl has to be handled before the container with nginx-proxy, so the external address of the docker registry domain has to be used.
Also the docker hosts firewall has to be configured (according to this link) to allow traffic from the docker container jenkins through to the docker host. At the host it then goes back again to docker registry via nginx-proxy with ssl, right? In my case, this comes down to:
$ sudo firewall-cmd --info-zone=public
public (active)
target: default
icmp-block-inversion: no
interfaces: enp6s0
sources:
[...]
rich rules:
rule family="ipv4" source address="172.26.0.13/32" accept

LibreOffice (soffice) issue while converting on Amazon ec2

This is not a repost, I am asking for the Amazon ec2 instance ! Questions that others asked worked fine on my local machine, and those were solved, but not on Amazon.
There have been several reports regarding this problem, but nothing solved this issue for me.
To post a few solutions:
https://forum.openoffice.org/en/forum/viewtopic.php?p=88088
https://forum.openoffice.org/en/forum/viewtopic.php?f=16&t=4767&p=21890&hilit=jodconverter#p21890
https://forum.openoffice.org/en/forum/viewtopic.php?f=16&t=4767&p=21948&hilit=jodconverter#p21948
These are the steps I took:
On a fresh EC2 Amazon instance, I have installed the libre office commons
$sudo apt-get install libreoffice-common
And then Maven
To run the service I am using (tried as sudo as well)
$soffice -nologo -nofirststartwizard -headless -norestore -invisible
"-accept=socket,host=localhost,port=8100,tcpNoDelay=1;urp;"
All ports and all securities are open for the ec2 instance
This is my code
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
import java.io.File;
/**
* soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
*/
public class testrun {
public static void main(String[] args){
try {
File inputFile = new File("./test.html");
File outputFile = new File("./OK.pdf");
// connect to an OpenOffice.org instance running on port 8100
SocketOpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
connection.connect();
// convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// close the connection
connection.disconnect();
}catch (Exception e){e.printStackTrace();}
}
}
This is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>izbr</groupId>
<artifactId>izbr</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.artofsolving/jodconverter -->
<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<version>2.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.4.3</version>
</dependency>
</dependencies>
My Java version is
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~14.04-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
When I run
$mvn exec:java -Dexec.mainClass="testrun"
error is:
116 [testrun.main()] INFO com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection - connected
com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException: conversion failed: could not save output document
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(OpenOfficeDocumentConverter.java:144)
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.convertInternal(OpenOfficeDocumentConverter.java:120)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:104)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:74)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:70)
at testrun.main(testrun.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:294)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy26.storeToURL(Unknown Source)
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.storeDocument(OpenOfficeDocumentConverter.java:156)
at com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter.loadAndExport(OpenOfficeDocumentConverter.java:140)
... 11 more
Caused by: com.sun.star.ucb.InteractiveAugmentedIOException: an error occurred during file opening
at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:187)
at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:153)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:349)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:318)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:106)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:657)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:159)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:141)
... 14 more
I have tried all suggestions such listing the listening ports and then changing the port number for soffice. Also running as sudo, and so on.
No solution helped. I have done a chmod 777 on /usr/bin/soffice /usr/bin/X11/soffice but that did not work.
Please note that it is working on my mahcine, but not on Amazon ec2 even if all ports and services are open!
EDIT: This worked for me, adjust the steps to your code. Changing the permission to folders and other answers I found were simply not helpful at all. I figured this out myself.
Upgrade/Update the instance
$ sudo apt-get upgrade
$ sudo apt-get update
Install java jdk 8
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
$ sudo apt-get install oracle-java8-set-default
Install Maven
$ sudo add-apt-repository "deb http://ppa.launchpad.net/natecarlson/maven3/ubuntu precise main"
$ sudo apt-get update
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6DTHIS_IS_HEX_FROM_ERRORFA0101
$ sudo apt-get install maven3
$ sudo ln -s /usr/share/maven3/bin/mvn /usr/bin/mvn
$ sudo apt-get update
Install LibreOffice (full!), and then check if there is a common, ususally there is
$ sudo apt-get install libreoffice
$ sudo apt-get install libreoffice-common
Open a new tab just for testing the connection, ssh to EC2 and do
$ soffice -nologo -nofirststartwizard -headless -norestore -invisible "-accept=socket,host=localhost,port=8100,tcpNoDelay=1;urp;"
Go to a project/testing and adjust the pom.xml
$ nano pom.xml
<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<version>2.2.1</version>
</dependency>
Adjust the source code so that the line A is changed with the line B, making sure that in-file and out-file (if any) are the right paths, and that they exist
A: OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
B: SocketOpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
clean install the project with maven
$ mvn clean install
Run the project/test for example:
$ mvn exec:java -Dexec.mainClass="testrun"

Docker on Windows 10 with Maven

Try to run docker automated tests with Maven on Windows 10.
There are many issues with Windows 10 and docker.
Our code run great on Mac or Linux.
I run it from the Powershell but getting same issue from terminal (CMD)
It looks like a permission problem with Win10 for local shared folders but I am not sure.
VirtualBox 5.0.6
Docker version 1.8.2, build 0a8c2e3
The Maven plugin
<pluginManagement>
<plugins>
<plugin>
<groupId>org.jolokia</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.13.5</version>
</plugin>
</plugins>
</pluginManagement>
This is the error:
[ERROR] ←[31mDOCKER> invalid mode for volumes-from: /opt/myapp (Internal Server Error: 500)←[m
[ERROR] ←[31mDOCKER> Error occurred during container startup, shutting down...←[m
did anyone come across this error on Windows 10?
So after a long few weeks of rebuilding windows back to 8.0, 8.1 and 10 there are few tips for anyone trying the same tricks.
The error is because Docker doesn't have permissions to the drive I was running maven from.
Download VM and Git independently. When installing docker unselect the two from the automatic override.
dont install Kitematic. It doesnt work most of the time
Docker user has access to the user folder only, normally under C:Users\your-name/... you should run all mvn commands from that folder or sub-folder
docker ver 1.8.3 or later
Win 10 works well, CMD & Powershell. I personally prefer powershell as it have more features.
Make sure to close the VM properly after a session before reboot
docker-machine stop (instance)
I normally add 2 CPU and 8GRam to my VM, it makes Docker run faster and less likely to crash when running few containers. Like 8 mysql instances.
good luck!

Resources