Yourkit Agent - Docker Container

Questions about YourKit Java Profiler
Post Reply
gajendra
Posts: 1
Joined: Sun Mar 18, 2018 6:22 am

Yourkit Agent - Docker Container

Post by gajendra »

I have an application running in Docker containers needs profiling. There is no way for me to run this application outside of docker because of the environment.

Is there any proven way of doing this?
Anton Katilin
Posts: 6172
Joined: Wed Aug 11, 2004 8:37 am

Re: Yourkit Agent - Docker Container

Post by Anton Katilin »

To profile a Java application or a server running in a docker container, you should run it with the profiler agent, and then use remote profiling in the profiler UI, as described below.

On Docker side

(1) Add few lines to your image's Dockerfile.

(1.1) Install YourKit Java Profiler agents:

Code: Select all

RUN wget https://www.yourkit.com/download/YourKit-JavaProfiler-2017.02-b75.zip -P /tmp/ && \
  unzip /tmp/YourKit-JavaProfiler-2017.02-b75.zip -d /usr/local && \
  rm /tmp/YourKit-JavaProfiler-2017.02-b75.zip
(1.2) If you use Alpine Linux install libc6-compat:

Code: Select all

RUN apk add --no-cache libc6-compat
(1.3) Expose the profiler agent port.

For example, if you specify the port with the agent startup option port=10001 (see below), add the following line.

Code: Select all

EXPOSE 10001
Note: we use the same example port 10001 throughout these instructions. If you decide to change it, please ensure you have changed it everywhere.

(1.4) Load the agent to the JVM by adding the Java command line option -agentpath.

For example, if you start your application with

Code: Select all

java -jar my-app.jar
...do it like this:

Code: Select all

java -agentpath:/usr/local/YourKit-JavaProfiler-2017.02/bin/linux-x86-64/libyjpagent.so=port=10001 -jar my-app.jar
Please find detailed description of how to specify -agentpath and choose the agent startup options in https://www.yourkit.com/docs/java/help/agent.jsp

(2) After modifying Dockerfile don't forget to build the container.

(3) While running your docker container make the agent port visible with the option -p:

Code: Select all

 docker run -p 10001:10001 your-docker
Connect to the profiled application

When the application is running in the container, remotely connect to it from the profiler UI to perform profiling: https://www.yourkit.com/docs/java/help/ ... jsp#remote

Note: if you're running docker locally on your developer machine, connect to localhost.
Post Reply