Visit Azul.com Support

Recording a Dockerized Application

Table of Contents
Need help?
Schedule a consultation with an Azul performance expert.
Contact Us

As Docker is a "closed environment", it can be challenging to create a JFR recording of an application running in a Docker or Kubernetes environment. You can use different approaches, depending on the connections you have available and where you can store the recording. When you are using the jcmd tool, or record at startup, you can store the recording inside the container, or use a volume to make the file easier accessible.

Recording with jcmd via Docker

Use the jcmd tool via the command-line tool via docker exec to start and stop JFR recordings.

  1. Find the process ID of the Java application in the Docker container by opening a shell connection and executing the jcmd command:

     
    $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b94b5825a39f petclinic:1.0 "java -jar petclinic…" 57 seconds ago Up 56 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp agitated_cerf $ docker exec -it b94b5825a39f sh # jcmd 1 petclinic.jar 82 jdk.jcmd/sun.tools.jcmd.JCmd
  2. Start a JFR Recording in the Docker container, see JFR Command Line Options for a complete overview of the available options. You need to use Process ID 1, as jcmd has confirmed this is the ID of the running application inside the Docker.

     
    jcmd 1 JFR.start duration=30s settings=profile filename=/tmp/recording.jfr 1: Started recording 1. The result will be written to: /tmp/recording.jfr
  3. Close the shell:

     
    exit

Recording with jcmd via Kubernetes

Use the same approach with the jcmd tool in a Kubernetes environment if you have access to the system.

  1. Identify the pod and the container in which you want to start the JFR recording with the following commands:

    • kubectl get pods: list all pods.

    • kubectl describe pod <pod-name>: describe a specific pod and its containers.

  2. Start a recording whenever needed:

     
    kubectl exec -n namespace pod -- jcmd 1 JFR.start duration=180s filename=/tmp/my_recording.jfr

    See JFR Command Line Options for a complete overview of the available options.

Recording at JVM Startup

For detailed performance analysis, you might prefer to start a JFR recording directly when launching a Java process.

To start recording from JVM startup, add -XX:StartFlightRecording to the application’s Java command line. Use a comma "," for separation when using multiple options. For example, use a configuration like this in your Dockerfile:

 
$ CMD ["java", "-XX:StartFlightRecorder=duration=200s,filename=/tmp/recording.jfr", "-jar", "app.jar"]

See JFR Command Line Options for a complete overview of the available options.

Recording with Azul Mission Control

Use Azul Mission Control to connect directly to the application via JMX.

  1. Make sure the container is configured to allow a remote connection, as described on Prepare the Remote JVM.

  2. If you are using Kubernetes, contact an administrator to set up a connection between your computer and the configured port in the container.

  3. Configure a new connection in Azul Mission Control as described on Connect to a remote JVM.

  4. Start a JFR recording in Azul Mission Control as described here.

  5. Azul Mission Control stores the .jfr recording file on the system it’s running on.