【问题标题】:Docker not catching env varsDocker 没有捕获环境变量
【发布时间】:2019-06-14 09:21:14
【问题描述】:

我正在尝试通过 docker-compose 运行 3 个容器,包括 postgres、cassandra 和我的 webapp,其中有一个嵌入式 tomcat 服务器,其中一些依赖项为 ARP/Native。该库位于 jar 同一级别的名为“lib”的文件夹中。

我在 Windows 10 上运行 PoC(使用 linux 容器),然后将其移动到 CentOS 服务器,如果它在 PoC 上运行。我在网上搜索,似乎不是一个孤立的问题,但或者我没有找到解决方案,或者解决方案显示对我不起作用。这是我的 docker-compose.yml,所有相关文件/文件夹都存储在同一级别:

version: '3.1' 

services:
fulmar-webapp:
    container_name: "my-webapp"
    image: openjdk:11-jre-slim
    hostname: mywebapp
    volumes:
        - ./lib:/home/lib
        - ./fulmar-1.0.1-SNAPSHOT-exec.jar:/home/mywebapp-1.0.1-SNAPSHOT-exec.jar

    entrypoint:
        - java
        - -jar
        - /home/mywebapp-1.0.1-SNAPSHOT-exec.jar

    environment:
        - LD_LIBRARY_PATH:/home/lib

        - spring.datasource.url=jdbc:postgresql://postgresql:5432/mydb
        - spring.datasource.username=postgres
        - spring.datasource.password=postgres
        - spring.jpa.hibernate.ddlAuto=update

    network_mode: bridge    
    ports:
        - 8443:8443
        - 8080:8080
    links:
        - postgresql 
        - cassandra     

postgresql:

    container_name: "mydb"
    image: postgres:11.1-alpine
    restart: always
    environment:
        POSTGRES_DB: mydb
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: postgres
    volumes:
       - ./startup.sql:/docker-entrypoint-initdb.d/startup.sql 
       - postgresdata:/var/lib/postgresql/data

    ports:
        - 5432:5432
    network_mode: bridge


cassandra:
    container_name: "cassandra"
    image: cassandra
    ports:
        - 9042:9042
    network_mode: bridge

卷: postgresdata:

不确定是否没有正确地将文件夹映射到库,或者实际上没有安装卷。这正是我需要放在那里的环境变量: 环境=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/libraries/lib

我遇到的两个结果:

1-Tomcat 异常导致找不到库:

[ERROR][org.apache.catalina.util.LifecycleBase#log(175)] Failed to 
initialize component [Connector[org.apache.coyote.http11.Http11AprProtocol- 
8080]] | org.apache.catalina.LifecycleException: The configured protocol 
[org.apache.coyote.http11.Http11AprProtocol] requires the APR/native library 
which is not available

2-警告:未设置 LD_LIBRARY_PATH 变量。默认为空字符串。

提前谢谢大家

编辑:让您知道,一旦我运行 docker-compose up,并且我的应用程序抛出此异常,容器不再可用,因此我无法在其中运行任何命令

【问题讨论】:

    标签: java docker-compose shared-libraries


    【解决方案1】:

    你的语法错误,应该是这样的:

    environment:
        - LD_LIBRARY_PATH=/home/lib
    

    【讨论】:

    • 刚试了一下,还是一样的异常:[14/06/2019 10:53:10][ERROR][org.apache.catalina.util.LifecycleBase#log(175)] 失败初始化组件 [Connector[org.apache.coyote.http11.Http11AprProtocol-8080]] | org.apache.catalina.LifecycleException:配置的协议 [org.apache.coyote.http11.Http11AprProtocol] 需要 APR/native 库,该库不可用
    猜你喜欢
    • 2023-02-20
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-10
    • 2020-12-07
    • 2021-12-19
    相关资源
    最近更新 更多