docker容器中解决java使用ffmpeg解析视频文字内容报错java.lang.UnsatisfiedLinkError:libxcb.so.1
Posted 学编程的司马光
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker容器中解决java使用ffmpeg解析视频文字内容报错java.lang.UnsatisfiedLinkError:libxcb.so.1相关的知识,希望对你有一定的参考价值。
java.lang.UnsatisfiedLinkError:libxcb.so.1: cannot open shared object file: No such file or directory
报错内容如下:
2022-12-22 11:10:56.884 DEBUG 6 --- [http-nio-9078-exec-1] o.s.b.w.s.f.OrderedRequestContextFilter : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@79634772
2022-12-22 11:10:56.889 ERROR 6 --- [http-nio-9078-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.UnsatisfiedLinkError: no jniavdevice in java.library.path] with root cause
java.lang.UnsatisfiedLinkError: /root/.javacpp/cache/ffmpeg-4.2.2-1.5.3-linux-x86_64.jar/org/bytedeco/ffmpeg/linux-x86_64/libjniavdevice.so: libxcb.so.1: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method) ~[na:1.8.0_265]
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934) ~[na:1.8.0_265]
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817) ~[na:1.8.0_265]
at java.lang.Runtime.load0(Runtime.java:810) ~[na:1.8.0_265]
at java.lang.System.load(System.java:1088) ~[na:1.8.0_265]
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1581) ~[javacpp-1.5.3.jar!/:1.5.3]
at org.bytedeco.javacpp.Loader.load(Loader.java:1265) ~[javacpp-1.5.3.jar!/:1.5.3]
at org.bytedeco.javacpp.Loader.load(Loader.java:1109) ~[javacpp-1.5.3.jar!/:1.5.3]
at org.bytedeco.ffmpeg.global.avdevice.<clinit>(avdevice.java:28) ~[ffmpeg-4.2.2-1.5.3.jar!/:4.2.2-1.5.3]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_265]
at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_265]
at org.bytedeco.javacpp.Loader.load(Loader.java:1176) ~[javacpp-1.5.3.jar!/:1.5.3]
at org.bytedeco.javacpp.Loader.load(Loader.java:1125) ~[javacpp-1.5.3.jar!/:1.5.3]
at com.everestfortune.cf.utils.VideoToAudio.convertMP4toPCM(VideoToAudio.java:57) ~[classes!/:0.0.1-SNAPSHOT]
at com.everestfortune.cf.service.impl.BaiDu_OCR_ServiceImpl.videoCheck(BaiDu_OCR_ServiceImpl.java:532) ~[classes!/:0.0.1-SNAPSHOT]
at com.everestfortune.cf.controller.VideoCheckController.videoCheck(VideoCheckController.java:58) ~[classes!/:0.0.1-SNAPSHOT]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_265]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_265]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_265]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_265]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) ~[spring-webmvc-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158) ~[spring-boot-actuator-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126) ~[spring-boot-actuator-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:111) ~[spring-boot-actuator-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) ~[druid-1.0.29.jar!/:1.0.29]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:84) ~[spring-boot-actuator-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_265]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_265]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.29.jar!/:8.5.29]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_265]
解决方法:有三种
1:在dockerfile的第一句from的镜像文件的容器中执行命令:
apt-get update && apt-get install libxcb1
这个方法每次重新发布,重新生成了新的容器后,就需要去容器中执行一次,比较麻烦
2:在构造镜像的dockerfile文件中增加命令:
RUN apt-get update && apt-get install libxcb1
这种方法每次构造镜像的时候会久一点,因为多了一步安装libxcb1
3:在容器中执行命令:
apt-get update && apt-get install libxcb1
之后,CTRL+P+Q退出容器,使用命令docker ps -a 找到刚才的容器ID,
执行命令:
docker export 容器ID > jdklibxcb.tar
jdklibxcb.tar为包含已经有了libxcb1的镜像包文件,
再执行命令,从镜像文件加载生成新镜像 :
docker import - jdklibxcb < jdklibxcb.tar
使用命令docker images就可以看到有一个新的jdklibxcb镜像了。
将dockerfile第一句的from改成from jdklibxcb就好了,
比如原来dockerfile是
FROM openjdk:8
ADD accounting_auth-0.0.1-SNAPSHOT.jar accounting_auth-0.0.1-SNAPSHOT.jar
#容器启动后执行的操作
CMD java -jar accounting_auth-0.0.1-SNAPSHOT.jar
#更改容器时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/ /etc/localtime && echo > /etc/timezone
修改后dockerfile变成了
FROM jdklibxcb
ADD accounting_auth-0.0.1-SNAPSHOT.jar accounting_auth-0.0.1-SNAPSHOT.jar
#容器启动后执行的操作
CMD java -jar accounting_auth-0.0.1-SNAPSHOT.jar
#更改容器时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/ /etc/localtime && echo > /etc/timezone
综合下来,推荐第三种,做一个私有加过包的镜像,虽然前面麻烦点,但一次搞定,也不影响后续的发布
结束
使用 Java 和 Node.js 创建 Docker 容器
【中文标题】使用 Java 和 Node.js 创建 Docker 容器【英文标题】:Create Docker container with both Java and Node.js 【发布时间】:2017-10-01 20:33:51 【问题描述】:我不知道为什么我希望这会起作用:
# Dockerfile
FROM node:6
FROM java:8
但它并没有真正起作用 - 看起来第一个命令被忽略了,而第二个命令起作用了。
有没有一种直接的方法可以在 Docker 容器中同时安装 Node.js 和 Java?
最终我要解决的问题是运行 Selenium Webdriver 时出现 ENOENT 错误 -
[20:38:50] W/start - Selenium Standalone server encountered an error: Error: spawn java ENOENT
现在我认为这是因为容器中没有安装 Java。
【问题讨论】:
【参考方案1】:dockerfile 中的FROM
只是告诉 docker 应该从哪个镜像开始配置。您不能简单地将多个图像连接在一起。已经有多个容器镜像可用,它们提供预安装的 Java 8 和节点 JS。我不想专门推荐任何图片,但会将您定向到docker-hub,以便您自行搜索并使用最适合您需求的容器。
【讨论】:
【参考方案2】:您可以为每个生成的图像使用单个 FROM
。
尝试使用node
作为基础镜像并安装java。
Dockerfile
FROM node:latest
RUN apt-get -y install default-jre
您可以选择您需要的版本:
apt install default-jre
apt install openjdk-11-jre-headless
apt install openjdk-8-jre-headless
【讨论】:
是的,我想,但这意味着我要多花 30 多秒的时间安装 java - 如果它是一个图像,它会快得多... 在某些情况下,安装 java 需要一分钟,没有乐趣 如何在node中安装java作为基础镜像【参考方案3】:对你来说最好的方法是使用 java(它已被官方弃用,它建议你使用 openjdk
图像)并在其中安装 node。
所以,开始
FROM openjdk:latest
这将使用最新的openjdk镜像,此时为8u151
。然后安装node
和您可能需要的其他依赖项:
RUN apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_9.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh
您可能想在之后安装 grunt 之类的东西,所以这也可能会派上用场。
RUN npm install -g grunt grunt-cli
您总共将获得以下 Dockerfile:
FROM openjdk:latest
RUN apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_9.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh \
RUN npm install -g grunt grunt-cli
你可以从我的 gitlab repo here 克隆 Dockerfile
【讨论】:
我更新了我的答案以包含最新版本的节点,应该是 7 问题是这将在 Debian 上安装一个更旧版本的 nodejs - 我怎样才能获得更新版本的 npm 和 nodejs?对于nodejs,我使用“RUN curl -sL deb.nodesource.com/setup_6.x | sudo -E bash -”openjdk:latest
映像的最新版本使用 Oracle Linux(基于 Red Hat 的发行版)作为其基础,而不是 Debian。这意味着apt
不再可用,而需要使用yum
。
最新版openjdk:16-jdk-oraclelinux8
,可惜好像没有yum
了。
@MalcolmCrum openjdk oraclelinux8
图像使用 oraclelinux8
的精简版,它不再安装 yum
或 dnf
。相反,他们有microdnf
,您使用相同的方式(例如从Dockerfile
安装cron):RUN microdnf update -y && microdnf install -y cron
github.com/oracle/container-images/issues/…【参考方案4】:
使用节点 14 版,它对我来说非常适合:
FROM openjdk:latest
RUN apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh \
RUN npm install -g grunt grunt-cli
【讨论】:
【参考方案5】:你也可以使用node
镜像,然后安装default-jre
:
# Dockerfile
FROM node:latest
RUN apt-get -y install default-jre
你可以选择你需要的版本:
apt install default-jre
apt install openjdk-11-jre-headless
apt install openjdk-8-jre-headless
【讨论】:
【参考方案6】:这对我有用:
FROM openjdk:16-slim-buster
RUN apt-get update; apt-get install -y curl \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get install -y nodejs \
&& curl -L https://www.npmjs.com/install.sh | sh
【讨论】:
以上是关于docker容器中解决java使用ffmpeg解析视频文字内容报错java.lang.UnsatisfiedLinkError:libxcb.so.1的主要内容,如果未能解决你的问题,请参考以下文章