Features

Debug your Java applications in Docker using IntelliJ IDEA

The Docker integration enables you to build or pull Docker images and run Docker containers directly from IntelliJ IDEA. You can use special run configurations to run your application in a Docker container and see how it will behave in an environment identical to production. But what about debugging? Well, starting from version 2019.1 you can debug Java applications running in Docker containers directly from IntelliJ IDEA.

This article is outdatedDownload the latest version of IntelliJ IDEA and follow the steps listed in our Run and debug a Spring Boot application using Docker Compose tutorial.

An application running inside a Docker container is treated as a remote application, so you can attach the debugger to it. IntelliJ IDEA includes a special type of run/debug configuration for remote debugging. You create a remote debug configuration and add a special Before launch task for it: Launch Docker before debug, which defines the Docker configuration that you want to run and attach to.

Remote debug configuration for a Java application running in a Docker container

Now every time you run the remote debug configuration, it will run the container according to the Docker run configuration settings and then attach the debugger to the application in your container. When it hits a breakpoint, the debugger will stop and let you analyze the current state of the application, just like a normal debugging session.

Debug session of a Java application running in Docker

This can be used for any type of Docker run configuration: whether it is based on a built Docker image, a Dockerfile, or a Docker Compose file. For more information about remote debugging in a Docker container and tutorials with examples, see the IntelliJ IDEA documentation.

This improvement enhances the Docker integration for developers who often utilize containers in their workflow. It is available in IntelliJ IDEA Ultimate Edition starting from version 2019.1.

NOTE: Remote debugging in Docker containers is currently implemented for Java 8 and earlier versions. Support for Java 9+ will be added in the nearest future.

Let us know what you think about this feature in the comments below. If you have suggestions for improvement, file a ticket in YouTrack.

Follow us on Twitter: @intellijidea

image description

Discover more