Docker撰写:运行命令变量替换不起作用

时间:2018-04-19 20:16:03

标签: docker docker-compose dockerfile

问题

替换不适用于构建阶段

文件

docker-compose.yml(仅限kibana部分):

kibana:
        build:
            context: services/kibana
            args:
                KIBANA_VERSION: "${KIBANA_VERSION}"
        entrypoint: >
            /scripts/wait-for-it.sh elasticsearch:9200
            -s --timeout=${ELASTICSEARCH_INIT_TIMEOUT}
            -- /usr/local/bin/kibana-docker
        environment:
            ELASTICSEARCH_URL: http://elasticsearch:9200
        volumes:
            - ./scripts/wait-for-it.sh:/scripts/wait-for-it.sh
        ports:
            - "${KIBANA_HTTP_PORT}:5601"
        links:
            - elasticsearch
        depends_on:
            - elasticsearch
        networks:
            - frontend
            - backend
        restart: always

服务/ kibana的Dockerfile:

ARG KIBANA_VERSION=6.2.3
FROM docker.elastic.co/kibana/kibana:${KIBANA_VERSION}

USER root
RUN yum install -y which && yum clean all

USER kibana

COPY kibana.yml /usr/share/kibana/config/kibana.yml
RUN ./bin/kibana-plugin install https://github.com/sivasamyk/logtrail/releases/download/v0.1.27/logtrail-${KIBANA_VERSION}-0.1.27.zip
COPY logtrail.json /usr/share/kibana/plugins/logtrail/logtrail.json

EXPOSE 5601

Env文件(仅限kibana部分):

KIBANA_VERSION=6.2.3
KIBANA_HTTP_PORT=5601
KIBANA_ELASTICSEARCH_HOST=elasticsearch
KIBANA_ELASTICSEARCH_PORT=9200

实际输出(问题在于:替换不起作用)

#docker-compose up --force-recreate --build kibana

.........

Step 8/10 : RUN ./bin/kibana-plugin install https://github.com/sivasamyk/logtrail/releases/download/v0.1.27/logtrail-${KIBANA_VERSION}-0.1.27.zip
 ---> Running in d28b1dcb6348
Attempting to transfer from https://github.com/sivasamyk/logtrail/releases/download/v0.1.27/logtrail--0.1.27.zip
Attempting to transfer from https://artifacts.elastic.co/downloads/kibana-plugins/https://github.com/sivasamyk/logtrail/releases/download/v0.1.27/logtrail--0.1.27.zip/https://github.com/sivasamyk/logtrail/releases/download/v0.1.27/logtrail--0.1.27.zip-6.2.3.zip
Plugin installation was unsuccessful due to error "No valid url specified."
ERROR: Service 'kibana' failed to build: The command '/bin/sh -c ./bin/kibana-plugin install https://github.com/sivasamyk/logtrail/releases/download/v0.1.27/logtrail-${KIBANA_VERSION}-0.1.27.zip' returned a non-zero code: 70

预期输出(类似):

Step 8/10 : RUN ./bin/kibana-plugin install https://github.com/sivasamyk/logtrail/releases/download/v0.1.27/logtrail-${KIBANA_VERSION}-0.1.27.zip
 ---> Running in d28b1dcb6348
Attempting to transfer from https://github.com/sivasamyk/logtrail/releases/download/v0.1.27/logtrail-6.2.3-0.1.27.zip

1 个答案:

答案 0 :(得分:0)

我发布这个问题后5分钟后我找到了答案......该死的

解决方案很愚蠢,但有效:我只需要为新用户重新定义args。参见:

USER kibana

ARG KIBANA_VERSION=${KIBANA_VERSION}

解决方案如下:

$.ajax({

        url: "http://localhost:8080/users/login",
        method: 'POST',
        cors: true,
        data: dat,
        headers: {
            "Accept": 'application/json'
        },
        dataType: "application/json",
        success: function (response) {
            alert('YAY');
        },
        failure: function (response) {
            alert('Error', 'Invalid Credentials');
        }
    });