Docker - java netty_tcnative 的问题
Posted
技术标签:
【中文标题】Docker - java netty_tcnative 的问题【英文标题】:Docker - Problem with java netty_tcnative 【发布时间】:2019-09-06 13:15:38 【问题描述】:我正在尝试对 4 项服务进行 dockerize,但其中一项服务有问题。特别是,该服务实现为spring boot服务,使用google vision API。在构建图像并启动容器时,一切正常,直到它到达使用 google vision API 代码的部分。然后在运行容器时出现以下运行时错误:
netty-tcnative unavailable (this may be normal)
java.lang.IllegalArgumentException: Failed to load any of the given libraries: [netty_tcnative_linux_x86_64, netty_tcnative_linux_x86_64_fedora, netty_tcnative_x86_64, netty_tcnative]
at io.grpc.netty.shaded.io.netty.util.internal.NativeLibraryLoader.loadFirstAvailable(NativeLibraryLoader.java:104) ~[grpc-netty-shaded-1.18.0.jar!/:1.18.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl.loadTcNative(OpenSsl.java:526) ~[grpc-netty-shaded-1.18.0.jar!/:1.18.0]
at io.grpc.netty.shaded.io.netty.handler.ssl.OpenSsl.<clinit>(OpenSsl.java:93) ~[grpc-netty-shaded-1.18.0.jar!/:1.18.0]
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.defaultSslProvider(GrpcSslContexts.java:244) [grpc-netty-shaded-1.18.0.jar!/:1.18.0]
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:171) [grpc-netty-shaded-1.18.0.jar!/:1.18.0]
at io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts.forClient(GrpcSslContexts.java:120) [grpc-netty-shaded-1.18.0.jar!/:1.18.0]
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.buildTransportFactory(NettyChannelBuilder.java:385) [grpc-netty-shaded-1.18.0.jar!/:1.18.0]
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:435) [grpc-core-1.18.0.jar!/:1.18.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:223) [gax-grpc-1.42.0.jar!/:1.42.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:164) [gax-grpc-1.42.0.jar!/:1.42.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:156) [gax-grpc-1.42.0.jar!/:1.42.0]
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:157) [gax-1.42.0.jar!/:1.42.0]
at com.google.cloud.vision.v1.stub.GrpcImageAnnotatorStub.create(GrpcImageAnnotatorStub.java:84) [google-cloud-vision-1.66.0.jar!/:1.66.0]
at com.google.cloud.vision.v1.stub.ImageAnnotatorStubSettings.createStub(ImageAnnotatorStubSettings.java:120) [google-cloud-vision-1.66.0.jar!/:1.66.0]
at com.google.cloud.vision.v1.ImageAnnotatorClient.<init>(ImageAnnotatorClient.java:136) [google-cloud-vision-1.66.0.jar!/:na]
at com.google.cloud.vision.v1.ImageAnnotatorClient.create(ImageAnnotatorClient.java:117) [google-cloud-vision-1.66.0.jar!/:na]
at com.google.cloud.vision.v1.ImageAnnotatorClient.create(ImageAnnotatorClient.java:108) [google-cloud-vision-1.66.0.jar!/:na]
完整的错误日志文件可以在这个链接中找到: Complete Log File.
这是我的 docker-compose.yml 文件和导致问题的服务的 Dockerfile:
DockerFile
FROM maven:3.6.0-jdk-8-alpine
WORKDIR /app/back
COPY src src
COPY pom.xml .
RUN mvn clean package
FROM openjdk:8-jdk-alpine
RUN apk add --no-cache curl
WORKDIR /app/back
COPY --from=0 /app/back/target/imagescanner*.jar ./imagescanner.jar
COPY --from=0 /app/back/target/classes/API-Key.json .
ENV GOOGLE_APPLICATION_CREDENTIALS ./API-Key.json
EXPOSE 8088
ENTRYPOINT ["java", "-jar", "./imagescanner.jar"]
docker-compose.yml
version: '3'
services:
front:
container_name: demoLab_front
build: ./front
image: demolab/front:latest
expose:
- "3000"
ports:
- "8087:3000"
restart: always
back:
container_name: demoLab_backGCV
build: ./backGCV
image: demolab/backgcv:latest
depends_on:
- lab
ports:
- "8088:8088"
restart: always
lab:
container_name: demoLab_labGCV
build: ./lab
image: demolab/labgcv:latest
expose:
- "8089"
ports:
- "8089:8089"
restart: always
sift:
container_name: demoLab_labSIFT
build: ./detect-label-service
image: demolab/labsift:latest
expose:
- "5000"
ports:
- "5000:5000"
restart: always
编辑
经过一番谷歌搜索后,我发现:GRPC Java 示例不适用于 Alpine Linux,因为所需的 libnetty-tcnative-boringssl-static 依赖于 glibc。 Alpine 正在使用 musl libc,应用程序启动将失败,并显示类似于我的消息。 我发现 this project 尝试构建正确的图像,但对于很多人来说它似乎坏了(构建不适用于我的情况)
【问题讨论】:
我可以在日志中看到缺少依赖文件“libcrypt.so.1”。抑制:java.lang.UnsatisfiedLinkError中:/tmp/libio_grpc_netty_shaded_netty_tcnative_linux_x86_641095585491871975468.so:错误加载共享库libcrypt.so.1:没有这样的文件或目录(由/tmp/libio_grpc_netty_shaded_netty_tcnative_linux_x86_641095585491871975468.so需要)跨度> 你是对的,我只是编辑了回答为什么它丢失的问题 【参考方案1】:通过替换 Dockerfile 的这一行解决了问题:
FROM openjdk:8-jdk-alpine
用这一行:
FROM koosiedemoer/netty-tcnative-alpine
【讨论】:
【参考方案2】:问题:抑制:java.lang.UnsatisfiedLinkError: no netty_tcnative in java.library.path 在高山容器上。
有一个简单的解决方法:
apk add libressl
apk add openssl
ln -s /lib/ld-musl-x86_64.so.1 /lib/libcrypt.so.1
【讨论】:
以上是关于Docker - java netty_tcnative 的问题的主要内容,如果未能解决你的问题,请参考以下文章
Docker 插件:java.io.FileNotFoundException:/src/main/docker/Dockerfile gradle-docker 失败