Fully featured low overhead profiler for Java EE and Java SE platforms.
Easy to use performance and memory .NET profiler for Windows and Linux.
Performance monitoring and profiling of Jenkins, Bamboo, TeamCity, Gradle, Maven, Ant and JUnit.

Profiling in 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:

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

    RUN apk add --no-cache libc6-compat

    Latest libc6-compat installs some shared libraries to /lib64. This directory should be explicitly added to the shared library search path.

    ENV LD_LIBRARY_PATH=/lib64
  • (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.

    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

    java -jar my-app.jar

    ...do it like this:

    java -agentpath:/usr/local/YourKit-JavaProfiler-2021.3/bin/linux-x86-64/libyjpagent.so=port=10001,listen=all -jar my-app.jar

    Please find detailed description of how to specify -agentpath and choose the agent startup options here.

(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:

docker run -p 10001:10001 your-docker

Connect to the profiled application

When the application is running in the container, connect to it from the profiler UI to perform profiling.

Note: if you're running Docker locally on your developer machine, create a remote connection to localhost.

Notes on a special case: a container with restricted home directory

For security reasons, the user home directory in a docker container may not exist or be read-only.

In this case, the agent will use /tmp instead of <user home>/Snapshots as the default snapshot directory. The snapshot directory may be overridden with the startup option dir.

The profiler agent log file neither can be created in its normal location <user home>/.yjp/log. Should you need the agent log file for troubleshooting purposes, specify a writable directory for it with the startup option logdir.

YourKit uses cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By browsing our website, you consent to our use of cookies and other tracking technologies in accordance with the Privacy Policy.