How to Profile Java Applications in Docker Containers with JFR

Transcript:

Hi friends! In this video, I will show you how to profile Java applications in Docker containers using Java Flight Recorder. Java Flight Recorder (JFR) is a low-overhead profiling and diagnostic tool built into the OpenJDK, so you don't have to install it manually. We can profile the application right from the start, attach to a running application, or observe it in JDK Mission Control.

First, let's look at how to start a JFR recording at application startup. You can take any application—I'm using Spring PetClinic. The Dockerfile includes Liberica JDK Lite and minimalistic Alpaquita Linux. The most important option to enable JFR is ‘StartFlightRecording’, where you can set parameters like duration and filename. After building and running the container, you can retrieve the recording file from the ‘tmp’ directory using docker cp. The recorded data can be analyzed in JDK Mission Control, an open-source tool.

Now, let's see how to attach to a running container and profile it. Instead of enabling JFR at startup, we can use the ‘jcmd’ tool, which is part of the JDK. However, production images usually contain only the JRE, not the full JDK. To solve this, we use ephemeral containers—temporary containers that include the JDK and attach to the running application. By running an ephemeral container with ‘pid=container’, we can use ‘jcmd’ to start a JFR recording. After profiling, we retrieve the file with docker cp without restarting the main container.

Lastly, if you want to monitor a running application in real time, JDK Mission Control allows remote profiling. We modify the Dockerfile to enable remote JVM connections using JMX-related options like ‘jmxremote.port’ and ‘jmxremote.rmi.port’. After rebuilding and running the container with these options, we connect to the JVM in Liberica Mission Control. This lets us observe real-time performance metrics.

In this video, we covered how to profile Java applications in containers using Java Flight Recorder. In a future video, we will explore profiling containerized Java apps with Async Profiler, another low-overhead profiler. Don't forget to like this video, subscribe to our channel, and see you next time!

Summary

This video explains how to profile Java applications in Docker containers using Java Flight Recorder (JFR), a built-in OpenJDK tool. It covers three profiling methods: enabling JFR at application startup, attaching to a running container using an ephemeral container with `jcmd`, and monitoring real-time performance with JDK Mission Control via remote JVM connections. Step-by-step instructions are provided for configuring Dockerfiles, retrieving profiling data, and analyzing application performance.

About Catherine

Java developer passionate about Spring Boot. Writer. Developer Advocate at BellSoft

Social Media

Videos
card image
Oct 16, 2025
All 7 Java Garbage Collectors Explained

In this complete guide to Java garbage collection, you will learn how the JVM memory model works, understand the differences between the Serial, Parallel, G1, ZGC, Shenandoah, CMS, and Epsilon collectors, and determine which garbage collector is best suited for your application's performance — from single-threaded programs to massive terabyte-scale heaps.

Videos
card image
Oct 7, 2025
Master Java Profiling in 2025: Tools, Techniques, and Real-World Tips

In this complete guide to Java profiling, you will learn sampling and instrumentation techniques, compare the 7 best tools (JFR, VisualVM, Async Profiler, JProfiler, YourKit, Digma.ai, New Relic), and master how to detect memory leaks and analyze CPU usage.

Further watching

Videos
card image
Nov 6, 2025
Docker Container Image Security: 13 Best Practices

This video presents 13 practical recommendations for reducing your attack surface and detecting malicious activity more quickly. You’ll learn how to create simple, immutable, and deterministic images using multi-stage builds, distroless bases, and non-root users. We cover SBOM generation with Syft, provenance verification with Cosign, CVE scanning workflows, and secret management strategies. From choosing LTS base images like Alpaquita Linux to implementing host-level protections, these practices will help you confidently deliver secure containers. It’s ideal for Java developers, DevOps engineers, and architects building production-grade infrastructure.

Videos
card image
Oct 31, 2025
Vaadin Tutorial: From Spring Boot to Beautiful UI Fast

In this guide, I’ll show you how to build a fully functional Java application with authentication, data tables, filters, and a custom cyberpunk theme using Vaadin.

Videos
card image
Oct 23, 2025
Top 7 JavaFX Testing Mistakes You Need To Avoid!

Stop making these common JavaFX testing mistakes! No more random NullPointerExceptions or deadlocks — in this video, we’ll show you how to fix the 7 most frequent TestFX issues when testing JavaFX applications. Learn how to work with FX threads, integrate with Spring Boot, avoid event-queue race conditions, handle pixel-level test differences, set up headless continuous integration with Monocle, and properly separate business logic from UI tests.