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?
Yourkit Agent - Docker Container
-
- Posts: 6172
- Joined: Wed Aug 11, 2004 8:37 am
Re: Yourkit Agent - Docker Container
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:
(1.2) If you use Alpine Linux install 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.
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
...do it like this:
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:
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.
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
Code: Select all
RUN apk add --no-cache libc6-compat
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
(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
Code: Select all
java -agentpath:/usr/local/YourKit-JavaProfiler-2017.02/bin/linux-x86-64/libyjpagent.so=port=10001 -jar my-app.jar
(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
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.