Sap Java Connector Application in Docker - spring-boot

I am trying to build a sap java connector using springboot. To build this app we need sapjco3.jar and sapjco3.so.
I am using Hibersap library and have added the maven jar dependencies.
In the documentation it says to run the the app we need pass the java.library.path={path to the .so file} in java params.
The application is running fine in linux but I am facing :
Caused by: java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.UnsatisfiedLinkError: /usr/lib/libsapjco3.so: libuuid.so.1: cannot open shared object file: No such file or directory
when I am trying to run in Docker.
I have added this in my dockerfile. :
VOLUME ["/var/log/hip"]
ADD maven/#file# app.jar
COPY libsapjco3.so /usr/lib/libsapjco3.so
RUN chmod a+x -R /usr/lib/libsapjco3.so
RUN sh -c 'touch /app.jar'
CMD [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar --logging.path=/var/log/hip"]
and I am trying the path using:
System.setProperty("java.library.path","/usr/lib");
As I said, this is working in windows using dll and linux using but it is failing in docker running linux.

I had same problem (WSO2 Docker image and SAP integration), try to install "libuuid" package inside your Docker image. SAP connector was searching for libuuid, so I installed it and it started up. I was using Alpine Linux inside Docker image and this helped:
apk add libuuid

Related

Is the docker daemon running? Spring-boot java project on Ubuntu

I have Ubuntu 22.04,
I have Java Spring-boot project, I run Idea, then run docker-compose.yml and get this message:
Cannot connect to the docker daemon at unix:///var/run/docker.sock.
Is the docker daemon running? (Details:[13] Permission denied)
What should I check?
You can take this perfect Tutorial: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04
The important section for you is: Step 2 — Executing the Docker Command Without Sudo (Optional)
Your Problem is that you try to use docker without sudo. You have no permission for that.

Building a Docker Image with the Spring Boot Gradle Plugin and Colima

I'm trying to create a docker image of a Spring Boot application using the Gradle plugin. I'm using Spring Boot 2.6.4 and Gradle 7.1.1.
I'm on a Mac, and I don't have Docker Desktop installed. Indeed, I run docker using Colima.
The problem is that I cannot build the docker image with the command ./gradlew bootBuildImage since Gradle cannot find the docker daemon:
Connection to the Docker daemon at 'localhost' failed with error "[2] No such file or directory"; ensure the Docker daemon is running and accessible
Is there any configuration I have to do in Colima or my build.gradle file?
Colima creates a socket in the location ~/.colima/docker.sock by default. Running the command docker context ls should show a context named colima with the socket location shown in the DOCKER ENDPOINT column.
You can configure the Spring Boot Gradle plugin to use this socket by setting the DOCKER_HOST environment variable to unix:///Users/<user>/.colima/docker.sock or by adding the following to your build file as shown in the documentation.
tasks.named("bootBuildImage") {
docker {
host = "unix:///Users/<user>/.colima/docker.sock"
}
}

Docker - Spring boot application with profile

I have a docker image of a Spring boot application which is created by a developer from a different team. I'm trying to run this image on my Mac.
This application expects a profile name while starting the application. The properties file corresponding to that profile tries to locate a config file on the host machine.
Contents of application-local.properties
spring.config.import=file:/Users/userName/app.properties
Docker command I tried:
docker run -p 8080:8080 -e "JAVA_OPTS=-Dspring.profiles.active=local" application-name:0.0.1
This command fails with this exception as it is not able to access the file on the host machine.
01:09:20.764 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.boot.context.config.ConfigDataResourceNotFoundException: Config data resource 'file [/Users/userName/app.properties]' via location 'file:/Users/userName/app.properties' cannot be found
I tried to use the -v flag to bind this directory on the host to some directory on the container but it still failed.
docker run -p 8080:8080 -v /Users/userName:/app -e "JAVA_OPTS=-Dspring.profiles.active=local" application-name:0.0.1
Exception-
02:50:36.882 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.boot.context.config.ConfigDataResourceNotFoundException: Config data resource 'file [/Users/userName/app.properties]' via location 'file:/Users/userName/app.properties' cannot be found
The ENTRYPOINT of this docker image is:
/bin/sh -c #(nop) ENTRYPOINT ["/bin/sh" "-c" "exec java $JAVA_OPTS -XX:+UseContainerSupport -Djava.security.egd=file:/dev/./urandom -jar /opt/app/app.jar"]
How can I run this application on my machine? Am I missing anything? TIA.

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.

marathon start java program

I'm trying to deploy a test java program on mesos cluster using marathon. I've created a tar ball with all required jars and config files. The tar also has a cmd.sh that launches the app. Cmd.sh snippet
chmod a+rx *.jar
java -ea -Dlog4j.configuration="file:./log4j.prod.properties" -cp my-app-0.1-SNAPSHOT.jar:lib/* package.name.main.class.name
This tar is provided as an URI. I can see in log file that tar is downloaded and unpacked correctly. But execution fails with error
I0331 23:00:35.135365 30558 exec.cpp:134] Version: 0.27.1
I0331 23:00:35.137852 30588 exec.cpp:208] Executor registered on slave 11aaafce-f12f-4aa8-9e5c-200b2a657225-S1
./cmd.sh: line 5: java: command not found
Any idea why its not finding java? I'm not using any custom container. Only parameters I've set are id, cpu, mem, instance, uri and cmd=cmd.sh
Is this the recommended way to run java apps? My java program is stateless(uses zookeeper for state) and I intend to run several instance of this app. Please feel free to suggest alternate ways of launching or deploying such an app.
Please check the path when you run sh -c vs running the from tar.

Resources