Environment:
Go version: 1.14
Kibana version: 7.7.1
Elasticsearch version: 7.7.1
APM Server version: 7.7.1
APM Agent language and version: go get go.elastic.co/apm and go.elastic.co/apm/module/apmhttp
Browser version: Chrome MacOS
Original install method (e.g. download page, yum, deb, from source, etc.) and version: Docker-Compose
Is there anything special in your setup? No, just sending to the ElasticsSearch.
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
I have a docker-compose file as follow, and I export the URL APM Server to localhost (export ELASTIC_APM_SERVER_URL=http://localhost:8200). When I run my Golang application, everything works fine, the agent send the data to kibana and I see the metrics in the UI.
BUT, when I uncomment my application in docker-compose (see below), just to run everything with Docker, the agent sotp sending data. I think I might be because the ELASTIC_APM_SERVER_URL is set in my local machine, not inside the container. Do I have to export the ELASTIC_APM_SERVER_URL in Dockerfile too? I tried but I got the same result.
These are the docker-compose and Dockerfile files:
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data02:/usr/share/elasticsearch/data
ports:
- 9201:9201
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
ports:
- 9202:9202
networks:
- elastic
kib01:
image: docker.elastic.co/kibana/kibana:7.7.1
container_name: kib01
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://es01:9200
ELASTICSEARCH_HOSTS: http://es01:9200
networks:
- elastic
apm-server:
image: docker.elastic.co/apm/apm-server:7.7.1
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=kib01:5601
-E setup.template.settings.index.number_of_replicas=0
-E apm-server.kibana.enabled=true
-E apm-server.kibana.host=kib01:5601
-E output.elasticsearch.hosts=["es01:9200"]
healthcheck:
interval: 10s
retries: 12
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/
networks:
- elastic
# proxy:
# build: .
# ports:
# - "8080:8080"
# restart: on-failure
# networks:
# - elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: bridge
And the Dockerfile of my app:
FROM golang:1.14-alpine as builder
LABEL maintainer="Dario Boverio <darioboverio@gmail.com>"
RUN apk update && apk add --no-cache git
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main
# Start a new stage from scratch
FROM alpine:latest
WORKDIR /root/
COPY --from=builder /app/main .
#I don't know if I have to do something like this
#RUN export ELASTIC_APM_SERVER_URL=http://apm-server:8200
EXPOSE 8080
CMD ["./main"]
I tried everything but I couldn't figure out the problem.
Thanks in advance.
Best Regards,
Dario