Cannot write log info in log file in Docker

I have a problem about generating log info when I work in Docker. There is no issue to write logs in log file in localhost.

I cannot see any new logs when I implement the CRUD process during docker.

How can I connect log file(Springboot-Elk.log) to Docker?

How can I fix it?

Here is my project link : My Project

Here is the docker-compose.yml shown below

    version: '3.8'
services:
  logstash:
    image: docker.elastic.co/logstash/logstash:7.15.2
    user: root
    command: -f /etc/logstash/conf.d/
    volumes:
      - ./elk/logstash/:/etc/logstash/conf.d/
      - ./Springboot-Elk.log:/tmp/logs/Springboot-Elk.log
    ports:
      - "5000:5000"
    environment:
      LS_JAVA_OPTS: "-Xmx256m -Xms256m"
    depends_on:
      - elasticsearch

  filebeat:
    image: docker.elastic.co/beats/filebeat:7.15.2
    build:
      context: ./filebeat
      dockerfile: Dockerfile
    links:
      - "logstash:logstash"
    volumes:
      - /var/run/docker.sock:/host_docker/docker.sock
      - /var/lib/docker:/host_docker/var/lib/docker
    depends_on:
      - logstash
  kibana:
    image: docker.elastic.co/kibana/kibana:7.15.2
    user: root
    volumes:
      - ./elk/kibana/:/usr/share/kibana/config/
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch
    entrypoint: ["./bin/kibana", "--allow-root"]

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.15.2
    user: root
    volumes:
      - ./elk/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
  app:
    image: 'springbootelk:latest'
    build:
      context: .
      dockerfile: Dockerfile
    container_name: SpringBootElk
    depends_on:
      - db
      - logstash
    ports:
      - '8077:8077'
    environment:
      - SPRING_DATASOURCE_URL=jdbc:mysql://db:3306/springbootexample?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
      - SPRING_DATASOURCE_USERNAME=springexample
      - SPRING_DATASOURCE_PASSWORD=111111
      - SPRING_JPA_HIBERNATE_DDL_AUTO=update
  db:
    container_name: db
    image: 'mysql:latest'
    ports:
      - "3366:3306"
    restart: always
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      - db-data:/var/lib/mysql

# Volumes
volumes:
  db-data:

Here is logstash.conf shown below

    input {
        beats {
                port => 5000
        }
        file {
                path => "/tmp/logs/Springboot-Elk.log"
                sincedb_path => "/dev/null"
                start_position => "beginning"
        }
}
output {
        stdout{
                codec => rubydebug
        }
        elasticsearch {
                hosts => "elasticsearch:9200"
                index => "dockerlogs"
        }
}

As I want to see logs in logstash , I run this command docker container logs -f . I cannot see any logs defined in PersonController and PersonService there. Here is the screenshot enter image description here



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation