运行 jar 文件时在 docker 容器内加载 .so 库时出错

问题描述 投票:0回答:1

我试图在 docker 容器内运行 java spring boot 应用程序。 jar 文件 (testapp.jar) 包含所有依赖项,其中一个依赖项包含一个 .so (libjsimplerdma.so) 库。当我运行图像时,它抛出以下异常:

java.lang.UnsatisfiedLinkError: /tmp/jxio8802823867088/libjsimplerdma.so: libsimplerdma.so: cannot open shared object file: No such file or directory

我的 Dockerfile 有:

FROM centos:7
WORKDIR /
RUN yum update -y \
   && yum -y install gcc glibc glibc-common \
   && yum -y install cmake \
   && yum -y install epel-release \
   && yum -y install python python-pip libxslt-devel python-devel libxml2- devel \
   && yum -y install java \
   && yum -y clean all

COPY testapp.jar /var/lib/test-app/testapp.jar
COPY application.properties /var/lib/test-app/application.properties
ADD run-test-app.sh /

USER root
ENTRYPOINT ["/run-test-app.sh"]

在 run-test-app.sh 中,我有:

#!/bin/bash

echo "Starting testapp"
cd /var/lib/test-app
java -Djava.library.path=/tmp/ -jar testapp.jar -- spring.config.location=/var/lib/test-app/  

testapp.jar 包含 jtest-rdma.jar,其中包含 libjsimplerdma.so 文件:

在testapp.jar中:

38713 Wed Feb 27 11:55:10 EST 2019 BOOT-INF/lib/jtest-rdma.jar

jtest-rdma.jar 有 libjsimplerdma.so:

19024 Wed Feb 27 11:55:10 EST 2019 libjsimplerdma.so

当我用docker运行镜像时,出现以下错误:

Native code library failed to load
java.lang.UnsatisfiedLinkError: /tmp/jxio8802823867088/libjsimplerdma.so: libsimplerdma.so: cannot open shared object file: No such file or directory

当我检查

/tmp
时,我只看到创建了一个目录
jxio8802823867088
,但里面没有文件。

如果我在本地运行 jar (没有 docker 容器),它工作正常。

我不确定我在这里错过了什么?

java docker .so
1个回答
0
投票

我有同样的问题,我正在尝试使用 spring-boot 应用程序将 file.so 加载到 podman 容器中

FROM registry.access.redhat.com/ubi8/ubi-minimal
ENV SPRING_PROFILES_ACTIVE=dev-profile

# Copy the JAR file to the workdir
COPY /myapi-boot/target/myapi-boot.jar /myapi-boot.jar

ENTRYPOINT [\
"java",\
"-Xms256m",\
"-Xmx512m",\
"-jar",\
"-Djava.library.path=/libjpeg-turbo/bin/",\
"-Dspring.profiles.active=${SPRING_PROFILES_ACTIVE}",\
"/myapi-boot.jar"\
]

我正在使用支架:

docker run --name apiturbo -p 9026:9026 -e "SPRING_PROFILES_ACTIVE=dev-profile" --mount type=bind,source=/home/bis/BIS_Interfaces_Deploy/config/bis-documents-api/libjpeg-turbo/bin/,target=/libjpeg-turbo/bin/  myapi

错误是:

no libturbojpeg in java.library.path: /libjpeg-turbo/bin/

“java.lang.UnsatisfiedLinkError:java.library.path中没有libturbojpeg:/libjpeg-turbo/bin/

有没有人能解决这个问题?

提前致谢

© www.soinside.com 2019 - 2024. All rights reserved.