docker运行声网linux-server-sdk示例

简介: docker运行声网linux-server-sdk示例

首先是下载:

下载 - 云信令(原实时消息) - 文档中心 - 声网Agora

Agora_RTM_SDK_for_Linux_Java_v1_5_1.zip其中有个samples/Agora-RTM-Tutorial-Java,我们将

libs/libagora_rtm_sdk.so

libs/agora_rtm.jar

复制到samples/Agora-RTM-Tutorial-Java/lib

然后在samples/Agora-RTM-Tutorial-Java下执行命令:

mvn install:install-file -Dfile=lib/agora_rtm.jar -DgroupId=io.agora.rtm  -DartifactId=agora-rtm-sdk -Dversion=1.0 -Dpackaging=jar

然后注意修改代码中的AppIdtoken

这里我的token采取服务端生成,因此我们还需要这一个jar

<dependency>
    <groupId>io.agora</groupId>
    <artifactId>authentication</artifactId>
    <version>2.0.0</version>
</dependency>

代码:

String token = new RtmTokenBuilder2().buildToken(appId, appCertificate, userId, 3600);

其次是Dockerfile,我放在Agora-RTM-Tutorial-Java

# 使用基础的Java 8镜像(包含编译工具)作为基础
FROM openjdk:17-jdk

# 设置工作目录
WORKDIR /app

# 复制示例代码和Agora RTM库文件到容器中
COPY . /app

# 暴露所需的端口,如果需要的话
EXPOSE 8080

# 编译示例代码
RUN javac -cp lib/agora_rtm.jar:lib/agora_rtm.jar:lib/authentication-2.0.0.jar:lib/commons-codec-1.11.jar -d . src/main/java/io/agora/RtmJavaDemo.java

# 定义入口命令来运行示例代码
CMD ["java", "-cp", "lib/*:.", "-Djava.library.path=/app/lib", "io.agora.RtmJavaDemo"]

然后是构建镜像、运行

docker build -t agora-rtm-demo:java17 .
docker run -it --rm -p 8080:8080 agora-rtm-demo:java17

然后杯具了,不支持macAARCH64架构芯片

Github-Id-VampireAchao:Agora-RTM-Tutorial-Java achao$ docker build -t agora-rtm-demo:java17 .
[+] Building 1.8s (9/9) FINISHED                                                                                                                                                                                     docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                                                                 0.0s
 => => transferring dockerfile: 614B                                                                                                                                                                                                 0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                    0.0s
 => => transferring context: 2B                                                                                                                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/openjdk:17-jdk                                                                                                                                                                    1.7s
 => [1/4] FROM docker.io/library/openjdk:17-jdk@sha256:528707081fdb9562eb819128a9f85ae7fe000e2fbaeaf9f87662e7b3f38cb7d8                                                                                                              0.0s
 => [internal] load build context                                                                                                                                                                                                    0.0s
 => => transferring context: 2.95kB                                                                                                                                                                                                  0.0s
 => CACHED [2/4] WORKDIR /app                                                                                                                                                                                                        0.0s
 => CACHED [3/4] COPY . /app                                                                                                                                                                                                         0.0s
 => CACHED [4/4] RUN javac -cp lib/agora_rtm.jar:lib/hutool-all-5.8.20.jar:lib/agora_rtm.jar:lib/authentication-2.0.0.jar:lib/commons-codec-1.11.jar -d . src/main/java/io/agora/RtmJavaDemo.java                                    0.0s
 => exporting to image                                                                                                                                                                                                               0.0s
 => => exporting layers                                                                                                                                                                                                              0.0s
 => => writing image sha256:499b1a69d4889983fe3da9ad61dbce252495c50f29672f806bf6916faa3a2a81                                                                                                                                         0.0s
 => => naming to docker.io/library/agora-rtm-demo:java17                                                                                                                                                                             0.0s

What's Next?
  1. Sign in to your Docker account → docker login
  2. View a summary of image vulnerabilities and recommendations → docker scout quickview
Github-Id-VampireAchao:Agora-RTM-Tutorial-Java achao$ docker run -it --rm -p 8080:8080 agora-rtm-demo:java17
Exception in thread "main" java.lang.UnsatisfiedLinkError: /app/lib/libagora_rtm_sdk.so: /app/lib/libagora_rtm_sdk.so: cannot open shared object file: No such file or directory (Possible cause: can't load AMD 64 .so on a AARCH64 platform)
        at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
        at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
        at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
        at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:287)
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422)
        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
        at java.base/java.lang.System.loadLibrary(System.java:1989)
        at io.agora.common.AgoraServiceJNI.ensureNativeInitialized(AgoraServiceJNI.java:26)
        at io.agora.common.AgoraServiceJNI.<clinit>(AgoraServiceJNI.java:21)
        at io.agora.common.Logging.log(Logging.java:26)
        at io.agora.common.Logging.i(Logging.java:50)
        at io.agora.rtm.internal.RtmClientImpl.initRtmService(RtmClientImpl.java:116)
        at io.agora.rtm.internal.RtmClientImpl.<init>(RtmClientImpl.java:101)
        at io.agora.rtm.internal.RtmManager.createRtmInstance(RtmManager.java:16)
        at io.agora.rtm.RtmClient.createInstance(RtmClient.java:64)
        at io.agora.RtmJavaDemo.init(RtmJavaDemo.java:60)
        at io.agora.RtmJavaDemo.main(RtmJavaDemo.java:239)

解决方案:jetbrains-gateway远端开发

相关文章
|
14天前
|
监控 Unix Linux
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
Linux操作系统调优相关工具(四)查看Network运行状态 和系统整体运行状态
29 0
|
28天前
|
Linux 编译器 程序员
【Linux 调试秘籍】深入探索 C++:运行时获取堆栈信息和源代码行数的终极指南
【Linux 调试秘籍】深入探索 C++:运行时获取堆栈信息和源代码行数的终极指南
67 0
|
14天前
|
Linux
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
21 0
|
1天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
9 0
|
14天前
|
Linux Shell 虚拟化
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
linux 部署docker容器虚拟化平台(二)--------docker 镜像制作方法
21 0
|
21天前
|
Ubuntu Unix Linux
【Linux/Ubuntu】Linux/Ubuntu运行python脚本
【Linux/Ubuntu】Linux/Ubuntu运行python脚本
|
21天前
|
Linux
Linux驱动运行灯 Heartbeat
Linux驱动运行灯 Heartbeat
10 0
|
22天前
|
Java Linux
Linux运行jar并选择配置文件
Linux运行jar并选择配置文件
8 1
|
22天前
|
Linux Docker 容器
Linux彻底卸载Docker包括运行拉取的镜像
Linux彻底卸载Docker包括运行拉取的镜像
22 1
|
3月前
|
安全 开发工具 Android开发
几个Flutter常见诊断错误与解决Android toolchain - develop for Android devices X Unable to locate Android SDK
几个Flutter常见诊断错误与解决Android toolchain - develop for Android devices X Unable to locate Android SDK
260 0