How to get elastic logs in a binded docker volume?

I want to access the logs of elasticsearch while it's running in a docker container. The goal is to keep track of possible errors while indexing documents.
I'm using the following docker-compose and I run it with sudo docker-compose up

version: '3.3'
services:
   
  elasticsearch1:
    restart: always
    image: elasticsearch:${ELK_VERSION}
    ports:
      - ${ES_PORT_HTTP}:9200
    volumes:
      - ./elasticsearch/data1:/usr/share/elasticsearch/data
      - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - ./elasticsearch/logs:/usr/share/elasticsearch/logs
    environment:
      - node.name=elasticsearch1
      - discovery.seed_hosts=elasticsearch2
      - cluster.initial_master_nodes=elasticsearch1, elasticsearch2
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS: -Xmx1g -Xms1g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    networks:
      - ni-network

  elasticsearch2:
    restart: always
    image: elasticsearch:${ELK_VERSION}
    volumes:
      - ./elasticsearch/data2:/usr/share/elasticsearch/data
      - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    environment:
      - node.name=elasticsearch2
      - discovery.seed_hosts=elasticsearch1
      - cluster.initial_master_nodes=elasticsearch1, elasticsearch2
      - "ES_JAVA_OPTS: -Xmx1g -Xms1g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    networks:
      - ni-network


networks:
  ni-network:
    external: true

Is it the right way to proceed ?
I can't start this compose because of the following :

elasticsearch1_1_9fc8d5261881 | Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
elasticsearch1_1_9fc8d5261881 | output:
elasticsearch1_1_9fc8d5261881 | [0.000s][error][logging] Error opening log file 'logs/gc.log': Permission denied
elasticsearch1_1_9fc8d5261881 | [0.000s][error][logging] Initialization of output 'file=logs/gc.log' using options 'filecount=32,filesize=64m' failed.
elasticsearch1_1_9fc8d5261881 | error:
elasticsearch1_1_9fc8d5261881 | OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
elasticsearch1_1_9fc8d5261881 | Invalid -Xlog option '-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m', see error log for details.
elasticsearch1_1_9fc8d5261881 | Error: Could not create the Java Virtual Machine.
elasticsearch1_1_9fc8d5261881 | Error: A fatal exception has occurred. Program will exit.
elasticsearch1_1_9fc8d5261881 | 	at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:111)
elasticsearch1_1_9fc8d5261881 | 	at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:79)
elasticsearch1_1_9fc8d5261881 | 	at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:57)
elasticsearch1_1_9fc8d5261881 | 	at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:89)

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