# Elastic APM Java Agent in Docker - Connection Refused

**URL:** <https://discuss.elastic.co/t/elastic-apm-java-agent-in-docker-connection-refused/302132>\
**Category:** APM\
**Tags:** docker, java, elastic-agent\
**Created:** [April 11, 2022, 3:57pm UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-in-docker-connection-refused/302132 "2022-04-11T15:57:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamuelSMendes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samuelsmendes/32/104246_2.png) [@SamuelSMendes](https://discuss.elastic.co/u/SamuelSMendes)\
**Post date:** [April 11, 2022, 3:57pm UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-in-docker-connection-refused/302132/1 "2022-04-11T15:57:16Z")

</div>

**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

```auto
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:

```auto
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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [April 11, 2022, 4:18pm UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-in-docker-connection-refused/302132/2 "2022-04-11T16:18:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [April 11, 2022, 4:21pm UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-in-docker-connection-refused/302132/3 "2022-04-11T16:21:22Z")

</div>

> <https://stackoverflow.com/questions/46973456/docker-access-localhost-port-from-container>

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

---

<div class="post-metadata">

**Author:** ![SamuelSMendes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samuelsmendes/32/104246_2.png) [@SamuelSMendes](https://discuss.elastic.co/u/SamuelSMendes)\
**Post date:** [April 11, 2022, 4:40pm UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-in-docker-connection-refused/302132/4 "2022-04-11T16:40:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 2, 2022, 12:41pm UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-in-docker-connection-refused/302132/5 "2022-05-02T12:41:11Z")

</div>

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