Docker未捕获环境变量

时间:2019-06-14 09:21:14

标签: java docker-compose shared-libraries

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

如果PoC可以在PoC上运行,我会先在Windows 10上运行PoC(使用linux容器),然后再将其移至CentOS服务器。我在网上搜索,似乎不是一个孤立的问题,或者我找不到解决方案,或者显示的解决方案对我没有用。这是我的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:

不确定该文件夹是否与库正确映射,或者是否未实际装入该卷。这正是我需要放在其中的Enviroment var: 环境= 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,并且我的应用抛出此异常,容器将不再可用,因此我将无法在其中运行任何命令

1 个答案:

答案 0 :(得分:0)

语法错误,应该是这样:

function jquery() {
    return gulp.src(["node_modules/jquery/dist/**/*.*"])
        .pipe(gulp.dest("wwwroot/lib/jquery/dist"));
};
gulp.task(jquery);


function jqueryValidation() {
    return gulp.src(["node_modules/jquery-validation/dist/**/*.*"])
        .pipe(gulp.dest("wwwroot/lib/jquery-validation/dist"));
};
gulp.task(jqueryValidation);


function jqueryValidationUnobtrusive() {
    return gulp.src(["node_modules/jquery-validation-unobtrusive/dist/**/*.*"])
        .pipe(gulp.dest("wwwroot/lib/jquery-validation-unobtrusive/dist"));
};
gulp.task(jqueryValidationUnobtrusive);


function jqueryValidationUnobtrusiveBootstrap() {
    return gulp.src(["node_modules/jquery-validation-unobtrusive-bootstrap/dist/**/*.*"])
        .pipe(gulp.dest("wwwroot/lib/jquery-validation-unobtrusive-bootstrap/dist"));
};
gulp.task(jqueryValidationUnobtrusiveBootstrap);


function jqueryAll(done) {
    parallel(jquery, jqueryValidation, jqueryValidationUnobtrusive, jqueryValidationUnobtrusiveBootstrap);
    done();
}
gulp.task(jqueryAll);