Not able to run the script to create dashboard in docker kibana


(Vikrant Aggarwal) #1

I am using the following compose file. My objective is to create the kibana dashboard automatically when the docker container starts hence I created customize image for kibana.

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
    container_name: elasticsearch
    environment:
      - "discovery.type=single-node"
      - "xpack.security.enabled=false"
      - "xpack.monitoring.enabled=false"
    volumes:
      - esdata:/usr/share/elasticsearch/data:rw
    ports:
      - 9200:9200
    networks:
      - elk
    restart: unless-stopped
  kibana:
    depends_on:
    - elasticsearch
    #image: docker.elastic.co/kibana/kibana:6.2.4
    image: ervikrant06/kibana:6.2.4.v1
    environment:
      - "xpack.monitoring.enabled=false"
    networks:
      - elk
    ports:
      - 5601:5601
    restart: unless-stopped
    command: sh bp-dashboard.sh
  logstash:
    image: ervikrant06:logstashv3
    #image: docker.elastic.co/logstash/logstash:6.2.4
    depends_on:
      - elasticsearch
    networks:
      - elk
    environment:
      - "xpack.security.enabled=false"
      - "INPUT1=/var/tmp/log"
      - "xpack.monitoring.enabled=false"
    restart: unless-stopped
    #volumes:
      #- /tmp/logstash/:/var/tmp/log
      #- /root/elk-logparser/pipeline/:/usr/share/logstash/pipeline/
volumes:
  esdata:
    driver: local
networks:
  elk:

Following is the dockerfile used to create kibana image:

# cat kibana/Dockerfile
FROM docker.elastic.co/kibana/kibana:6.2.4
ADD . /usr/share/kibana

content of the script which is used to issue curl POST command.

# cat bp-dashboard.sh
#!/bin/bash
sleep 30
curl -XPOST kibana:5601/api/kibana/dashboards/import -H 'kbn-xsrf:true' -H 'Content-type:application/json' -d @/usr/share/kibana/bp-dashboard.json

I have already verified that after running the container using docker run command I am able to run the script inside the container without any issue.

This is what i have seen on the screen after running docker-compose up.

kibana_1         |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
kibana_1         |                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed connect to kibana:5601; Connection refused
kibana_1         |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
kibana_1         |                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed connect to kibana:5601; Connection refused
kibana_1         |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
kibana_1         |                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed connect to kibana:5601; Connection refused

Anyone can please help me to point what I am doing wrong here?


(swarmee.net) #2

I think the recommended approach is to have a short lived container outside Kibana for this.

See this example https://github.com/swarmee/projects/tree/master/elastic-stack-6.3


(Vikrant Aggarwal) #3

Many thanks John for your comment.

I tried your suggestion and modified my docker-swarm file referring your one.

Despite of adding the dependency still it's trying to start the sidecar container first and later on kibana and es.

# docker-compose up
Creating network "elk-logparser_elk" with the default driver
Creating volume "elk-logparser_esdata" with local driver
Creating elasticsearch ... done
Creating logstash      ... done
Creating kibana        ... done
Creating load-sample-data ... done
Attaching to elasticsearch, logstash, kibana, load-sample-data
logstash           | 2018/07/09 02:25:56 Setting 'xpack.monitoring.enabled' from environment.
logstash           | OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
load-sample-data   |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
load-sample-data   |                                  Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to kibana port 5601: Connection refused
load-sample-data exited with code 7

Here is my modified docker-compose.yml file.

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
    container_name: elasticsearch
    environment:
      - "discovery.type=single-node"
      - "xpack.security.enabled=false"
      - "xpack.monitoring.enabled=false"
    volumes:
      - esdata:/usr/share/elasticsearch/data:rw
    ports:
      - 9200:9200
    networks:
      - elk
    restart: unless-stopped
  kibana:
    container_name: kibana
    depends_on:
    - elasticsearch
    image: docker.elastic.co/kibana/kibana:6.2.4
    environment:
      - "xpack.monitoring.enabled=false"
    networks:
      - elk
    ports:
      - 5601:5601
    restart: unless-stopped
  logstash:
    image: ervikrant06:logstashv3
    container_name: logstash
    #image: docker.elastic.co/logstash/logstash:6.2.4
    depends_on:
      - elasticsearch
    networks:
      - elk
    environment:
      - "xpack.security.enabled=false"
      - "INPUT1=/var/tmp/log"
      - "xpack.monitoring.enabled=false"
    restart: unless-stopped
    #volumes:
      #- /tmp/logstash/:/var/tmp/log
      #- /root/elk-logparser/pipeline/:/usr/share/logstash/pipeline/
  configure_stack:
    depends_on:
      - kibana
    container_name: load-sample-data
    #build: ./load-sample-data
    image: elk-logparser_configure_stack
    command: ['/bin/bash', '-c', 'cat /tmp/sample/bp-dashboard.sh | tr -d "\r" | bash']
    networks:
      - elk
volumes:
  esdata:
    driver: local
networks:
  elk:

i am not able to understand why it's not honoring the depends_on condition mentioned in compose. If it then I believe everything will work fine.


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.