Search code examples
docker-composemount

Mount EBS to ELK in Docker


I am facing some issue in Docker which is installed on EC2 node in AWS.

I have installed ELK in docker using docker-compose and now able to see the logs using tcp filter (winston3-npm) . I have also attached one EBS volume in this EC2 instance , now i want to persist the logs in this EBS so that even if i terminate my EC2 instance and spawn a new instance using this EBS volume then i want to see all the old logs.

So, I am not able to mount a EBS volume to docker so that all my data can be preserved. Below is my docker-compose file .

Could anyone help me on this ?

version: '3.2'

services:
  elasticsearch:
    build:
      context: elasticsearch/
      args:
        ELK_VERSION: $ELK_VERSION
    volumes:
      - type: bind
        source: ./elasticsearch/config/elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
        read_only: true
    volumes:
      - type: bind
        source: ./elasticsearch/config/elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
        read_only: true
      - /data:/usr/share/elasticsearch/data/:rw


      #- type: volume
        #source: elasticsearch
        #target: /usr/share/elasticsearch/data
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
      ELASTIC_PASSWORD: changeme
    networks:
      - elk

  logstash:
    build:
      context: logstash/
      args:
        ELK_VERSION: $ELK_VERSION
    volumes:
      - type: bind
        source: ./logstash/config/logstash.yml
        target: /usr/share/logstash/config/logstash.yml
        read_only: true
      - type: bind
        source: ./logstash/pipeline
        target: /usr/share/logstash/pipeline
        read_only: true
    ports:
      - "5000:5000"
      - "9600:9600"
    environment:
      LS_JAVA_OPTS: "-Xmx256m -Xms256m"
    networks:
      - elk
    depends_on:
      - elasticsearch

  kibana:
    build:
      context: kibana/
      args:
        ELK_VERSION: $ELK_VERSION
    volumes:
      - type: bind
        source: ./kibana/config/kibana.yml
        target: /usr/share/kibana/config/kibana.yml
        read_only: true
    ports:
      - "5601:5601"
    networks:
      - elk
    depends_on:
      - elasticsearch

networks:
  elk:
    driver: bridge

volumes:
  elasticsearch:


Solution

  • I am able to resolve the issue...Have mentioned the EBS mounted directory path in docker.service file which exists inside the /lib/systemd/system/ and able to see all the docker respective data in ebs.

    Thank you all for helping me .