Using javaagent in Docker container

Hello,

Using docker compose, I have a added a volume (containing the agent jar) and I added the java opts to point to this jar.
Sorry to say that when the java application gets started the volume is not yet available and the agent is not loaded.
Does anybody have a suggestion how to add the java agent to a existing container?

KR Henk

(I am trying to run the microservices-demo/sockshop demo with the elastic api agent)

Hi @Henk_Stobbe , can you share your docker-compose file?

Hello,

FYI also added the agent jar to the container, but seems I get same result. When starting the app with agent by logging in to the running container works like a charm.

I will add compose in next reply,

KR Henk

version: '2'

services:
orders:
image: weaveworksdemos/orders:agent
hostname: orders
restart: always
user: "root:root"
cap_drop:
- all
cap_add:
- NET_BIND_SERVICE
read_only: false
tmpfs:
- /tmp:rw,noexec,nosuid
volumes:
- c:/users/nl19867:/volume
environment:
- JAVA_OPTS=-Xms64m -Xmx128m -XX:+UseG1GC -Djava.security.egd=file:/dev/urandom, javaagent:/volume/agent.jar

Hello Please be aware I am running docker on windows 10!!! I already tried to chown:chgrp but that does not work!

Hi @Henk_Stobbe ,
I added some instructions to existing orders Dockerfile:

FROM weaveworksdemos/msd-java:jre-latest

WORKDIR /usr/src/app
COPY orders.jar ./app.jar
COPY elastic-apm-agent-1.22.0 /usr/src/app/elastic-apm-agent.jar

RUN	chown -R ${SERVICE_USER}:${SERVICE_GROUP} ./app.jar

USER ${SERVICE_USER}

ENTRYPOINT ["/usr/local/bin/java.sh","-jar","./app.jar", "--port=80"]

before you need, package orders via mvn clean package
after I build docker image:

orders\docker\orders>docker build -t orders:elastic .

and in docker-compose.yml modified JAVA_OPTS with elastic apm agent java conigurations:

  orders:
    image: orders:elastic
    hostname: orders
    restart: always
    cap_drop:
      - all
    cap_add:
      - NET_BIND_SERVICE
    read_only: true
    tmpfs:
      - /tmp:rw,noexec,nosuid
    environment:
      - JAVA_OPTS=-javaagent:/usr/src/app/elastic-apm-agent.jar -Xms64m -Xmx128m -XX:+UseG1GC -Djava.security.egd=file:/dev/urandom -Dspring.zipkin.enabled=false -Delastic.apm.service=orders -Delastic.apm.server_url=http://apmserver:8200 -Delastic.apm.log_level=DEBUG
    ports:
      - "8082:80"

or, @Henk_Stobbe
you can add volume with elastic-apm-agent and run with:

  orders-compose:
    image: weaveworksdemos/orders:0.4.7
    hostname: orders
    restart: always
    cap_drop:
      - all
    cap_add:
      - NET_BIND_SERVICE
    read_only: true
    tmpfs:
      - /tmp:rw,noexec,nosuid
    volumes:
      - ./volume/elastic-apm-agent-1.22.0.jar:/usr/src/app/elastic-apm-agent-1.22.0.jar
    environment:
      - JAVA_OPTS=-javaagent:/usr/src/app/elastic-apm-agent-1.22.0.jar -Xms64m -Xmx128m -XX:+UseG1GC -Djava.security.egd=file:/dev/urandom -Dspring.zipkin.enabled=false -Delastic.apm.service_name=orders_volume -Delastic.apm.server_url=http://apmserver:8200 -Delastic.apm.log_level=DEBUG
    ports:
      - "8083:80"

Hello Kanagat,

Thx for your answers!

KR Henk

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