# Elastic APM Agent with Docker

**URL:** <https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862>\
**Category:** APM\
**Tags:** java\
**Created:** [February 4, 2020, 6:56pm UTC](https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862 "2020-02-04T18:56:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elasticapmuser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticapmuser/32/46189_2.png) [@elasticapmuser](https://discuss.elastic.co/u/elasticapmuser)\
**Post date:** [February 4, 2020, 6:56pm UTC](https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862/1 "2020-02-04T18:56:51Z")

</div>

**Kibana version** : 7.3.2

**Elasticsearch version** : 7.3.2

**APM Server version** :7.3.2

**APM Agent language and version** : Java and 1.12.0

I am trying to integrate APM agent with a spring boot application and I could make it work using following command

-javaagent:/var/tmp/elastic-apm-agent-1.12.0.jar -Delastic.apm.service\_name=apm-demo-service -Delastic.apm.server\_url=http://apmserver:8200 -Delastic.apm.application\_packages=com.myapp -Delastic.apm.hostname=myhost

When I do this, I see a log statement indicating that the apm server is up.

2020-02-05 00:24:42.648 [apm-server-healthcheck] INFO co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server is available: { "build\_date": "2019-09-06T13:16:25Z", "build\_sha": "ed1ac181088227b51686ac5affe8e4176a179ebf", "version": "7.3.2"}  
2020-02-05 00:24:43.015 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.12.0 as apm-demo-service on Java 1.8.0\_45 (Oracle Corporation) Windows 8.1 6.3

But my spring boot application runs as a docker container and when I update entrypoint to use same java agent, it does not work. I initially thought that its not getting the jar file and hence causing the data not to be pushed to APM server. But that was not the case. I realized that the console logs do not show anything from co.elastic package.

I am using --net=host and hence the apm server access is not an issue.

Question is - is there any specific configuration I need to do make javaagent work with docker? Is there any port that I need to expose? Are there any volumes that I need by default?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [February 5, 2020, 8:15am UTC](https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862/2 "2020-02-05T08:15:20Z")

</div>

Did I get you right that it works as expected when run from your Windows host but you have problems when trying to use the agent with Docker?

> [@elasticapmuser](#):
>
> I realized that the console logs do not show anything from co.elastic package.

Seems like the agent is not applied at all then. Could you share your Docker setup, especially your entrypoint.

> [@elasticapmuser](#):
>
> Question is - is there any specific configuration I need to do make javaagent work with docker? Is there any port that I need to expose? Are there any volumes that I need by default?

No special configuration is necessary, apart from attaching adding the `-javaagent` flag and the agent configuration. It's recommended to use environment variables to configure the agent (for example in `docker-compose.yaml`).

This is a working example of using the Java agent with Docker.

> <https://github.com/elastic/opbeans-java/blob/63468a2b8353c7078c22dd8e17b4b11322c26317/Dockerfile#L41-L47>

---

<div class="post-metadata">

**Author:** ![elasticapmuser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticapmuser/32/46189_2.png) [@elasticapmuser](https://discuss.elastic.co/u/elasticapmuser)\
**Post date:** [February 5, 2020, 9:22am UTC](https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862/3 "2020-02-05T09:22:49Z")

</div>

Thanks for your reply. Yes, its not working with docker. I tried changing the path of the jar file and I was hoping I will get **Error occurred during initialization of VM agent library failed to init: instrument** error. But the container was started without any issues.

Here is entry point for docker image.

`ENTRYPOINT java -javaagent:/var/tmp/elastic-apm-agent-1.12.0.jar -Delastic.apm.service_name=apm-demo-service -Delastic.apm.server_url=http://apmserver:8200 -Delastic.apm.application_packages=com.myapp -Delastic.apm.hostname=myhost -server -Djava.security.egd=file:/dev/./urandom -jar /opt/my-service/my-service.jar`

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [February 5, 2020, 10:49am UTC](https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862/4 "2020-02-05T10:49:23Z")

</div>

Seems like the entrypoint is ignored then. Can you share more from that `Dockerfile`?

Try to make some obvious errors, like providing a wrong jar name and see if it still works.

Which base image is your image based on?

---

<div class="post-metadata">

**Author:** ![elasticapmuser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticapmuser/32/46189_2.png) [@elasticapmuser](https://discuss.elastic.co/u/elasticapmuser)\
**Post date:** [February 5, 2020, 5:24pm UTC](https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862/5 "2020-02-05T17:24:41Z")

</div>

Entrypoint is not ignored, spring boot application runs fine. Only Javaagent is ignored ☹

Just to add, I am using [https://forge.puppet.com/puppetlabs/docker](https://forge.puppet.com/puppetlabs/docker) for running docker container.

If I run the docker container with javaagent locally on my windows machine it works.

Looks like the problem is compatibility with puppet module.

---

<div class="post-metadata">

**Author:** ![elasticapmuser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticapmuser/32/46189_2.png) [@elasticapmuser](https://discuss.elastic.co/u/elasticapmuser)\
**Post date:** [February 14, 2020, 8:33am UTC](https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862/6 "2020-02-14T08:33:59Z")

</div>

Answering this myself. It came out to be problem container using JRE. After I switched to using JDK, it worked.

Thanks

---

<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:** [March 6, 2020, 4:34am UTC](https://discuss.elastic.co/t/elastic-apm-agent-with-docker/217862/7 "2020-03-06T04:34:15Z")

</div>

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