Elastic APM Java Agent in Docker - Connection Refused

Kibana version: 7.16.3

Elasticsearch version: 7.16.3

APM Server version: 7.16.3

APM Agent language and version: elastic-apm-agent 1.30.0 (java .jar)

I've been trying to use APM Agent to monitor a Springboot application in a docker container but it keeps returning Connection Refused

hello-world_1  | 2022-04-11 15:18:36,522 [main] INFO  co.elastic.apm.agent.impl.ElasticApmTracer - Tracer switched to RUNNING state
hello-world_1  | 2022-04-11 15:18:36,523 [elastic-apm-server-healthcheck] WARN  co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server http://localhost:8200/ is not available (Connection refused)
hello-world_1  | 2022-04-11 15:18:36,529 [elastic-apm-remote-config-poller] ERROR co.elastic.apm.agent.configuration.ApmServerConfigurationSource - Connection refused

PS: If I do a curl localhost:8200 it work just fine.

Here is my Dockerfile:

FROM openjdk:17
ADD target/elastic-apm-agent-1.30.0.jar elastic-apm-agent-1.30.0.jar
ADD target/hello-world-0.1.0.jar hello-world-0.1.0.jar
EXPOSE 8080

CMD java -javaagent:elastic-apm-agent-1.30.0.jar -Delastic.apm.service_name=Teste -Delastic.apm.application_packages=org.example,org.another.example -Delastic.apm.server_url=http://localhost:8200 -jar hello-world-0.1.0.jar

Once the application start these logs come out:

hello-world_1  | 2022-04-11 15:47:21,800 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Error trying to connect to APM Server at http://localhost:8200/intake/v2/events. Although not necessarily related to SSL, some related SSL configurations corresponding the current connection are logged at INFO level.
hello-world_1  | 2022-04-11 15:47:21,800 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type JSON_WRITER with this error: Connection refused
hello-world_1  | 2022-04-11 15:47:21,800 [elastic-apm-server-reporter] INFO  co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 0 seconds (+/-10%)

I'm really newbie to the subject and still learning how to work with it, tried the solutions I found arround people with similar problems here but couldn't make it work...I'll be glad if there is anyone able to help!

What happens if you shell into the docker container and curl localhost:8200 from there?

1 Like

In order to access your local machine use host.docker.internal instead of localhost .

1 Like

It really worked! Thanks alot for the help it was so simple but I would never notice it!

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