How to configure APM server to docker-compose file
Asked Answered
H

1

5

I have a docker-compose.yml file that consists of elasticsearch & kibana. I am wanting to add the APM Server service in the docker-compose.yml file. Is there a way to configure the apm server to the .yml file? I was reading up on configuring apm server on docker but this is not what I am looking for since I am doing this with docker-compose.

My docker-compose file:

version: '3.8'

services:

  elasticsearch:
   container_name: elasticsearch
   image: docker.elastic.co/elasticsearch/elasticsearch:7.13.0
   ports:
    - 9200:9200
   volumes:
    - elasticsearch-data:/usr/share/elasticsearch/data
   environment:
    - xpack.monitoring.enabled=true
    - xpack.watcher.enabled=false
    - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    - discovery.type=single-node
   networks:
    - elastic

  kibana:
   container_name: kibana
   image: docker.elastic.co/kibana/kibana:7.13.0
   ports:
    - 5601:5601
   depends_on:
    - elasticsearch
   environment:
    - ELASTICSEARCH_URL=http://localhost:9200
    - xpack.apm.enabled=false
   networks:
    - elastic

  
networks:
  elastic:
    driver: bridge

volumes:
  elasticsearch-data:

Updated docker-compose.yml:

Would this be correct?

version: '3.8'

services:

  apm-server:
   container_name: apm-server
   image: docker.elastic.co/apm/apm-server:7.13.0
   ports:
    - 8200:8200
   depends_on:
     - elasticsearch
     - kibana
   networks:
    - elastic 

   command: >
     apm-server -e
       -E apm-server.rum.enabled=true
       -E setup.kibana.host=kibana:5601
       -E setup.template.settings.index.number_of_replicas=0
       -E apm-server.kibana.enabled=true
       -E apm-server.kibana.host=kibana:5601
       -E output.elasticsearch.hosts=["elasticsearch:9200"]
  
  elasticsearch:
   container_name: elasticsearch
   image: docker.elastic.co/elasticsearch/elasticsearch:7.13.0
   ports:
    - 9200:9200
   volumes:
    - elasticsearch-data:/usr/share/elasticsearch/data
   environment:
    - xpack.monitoring.enabled=true
    - xpack.watcher.enabled=false
    - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    - discovery.type=single-node
   networks:
    - elastic

  kibana:
   container_name: kibana
   image: docker.elastic.co/kibana/kibana:7.13.0
   ports:
    - 5601:5601
   depends_on:
    - elasticsearch
   environment:
    - ELASTICSEARCH_URL=http://localhost:9200
    - xpack.apm.enabled=false
   networks:
    - elastic

  
networks:
  elastic:
    driver: bridge

volumes:
  elasticsearch-data:
Holsworth answered 1/6, 2021 at 15:29 Comment(2)
It seems you should add another item "apm_server" similar to "kibana" but changing url and portKrever
@Krever I see, I updated the post would it be like how I did it?Holsworth
B
11

You need to add APM to your docker file like this:

  apm-server:
    image: docker.elastic.co/apm/apm-server:7.13.0
    cap_add: ["CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID"]
    cap_drop: ["ALL"]
    ports:
    - 8200:8200
    command: >
       apm-server -e
         -E apm-server.rum.enabled=true
         -E setup.kibana.host=kibana:5601
         -E setup.template.settings.index.number_of_replicas=0
         -E apm-server.kibana.enabled=true
         -E apm-server.kibana.host=kibana:5601
         -E output.elasticsearch.hosts=["elasticsearch:9200"]
    healthcheck:
      interval: 10s
      retries: 12
      test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/
Burette answered 2/6, 2021 at 8:58 Comment(3)
"Looks like you don't have any APM services installed. Let's add some!" Is it possible to set up apm so as the docker image could run it without any manual setup?Pelagianism
In version 8 this healthcheck doesn't work. I see that curl is not installed in container. I used for that this command: apm-server test output -E output.elasticsearch.username=${ELASTIC_USER} -E output.elasticsearch.password=${ELASTIC_PASSWORD}Parclose
Improved version on the above comment: test: ["CMD-SHELL", "! apm-server test output -E output.elasticsearch.username=${ELASTIC_USER} -E output.elasticsearch.password=${ELASTIC_PASSWORD} | grep -q ERROR" ]Parclose

© 2022 - 2024 — McMap. All rights reserved.