You're reading for free via Mammad Yahyayev's Friend Link. Become a member to access the best of Medium.

Member-only story

Docker Advance Part 8: How to Connect Docker Container Remotely From Your IDE

Mammad Yahyayev
DevOps.dev
Published in
4 min readFeb 4, 2025

Image generated by ChatGPT

My articles are open to everyone; non-member readers can read the full article by clicking this link.

Hello developers and DevOps enthusiast, welcome to the new part of my Docker Advance Series. In this part, we are going to connect to the Docker container from IDE to debug our application.

The Importance of Debugging

Gif Link

No need to explain how important debugging is. Imagine an application which doesn’t have enough logs to identify problems that happened on production. In these cases, it is nearly impossible to add more logs, redeploy the app and wait for the error to reproduce.

Debugging from your IDE makes the bug finding process easier because we see how our values changes in each line.

P.S: If you already solve the problem, try to add more logs for future problems like this. Trust me, it will worth it.

How to Connect Docker Container Remotely from IDE?

I will create a Spring Boot application for this demo. This app contains one POST endpoint which accepts firstName and lastName as request parameters.

At first, we are going to create Docker Image for application, then we will connect via IntelliJ IDEA remote debugger.

How to Create Docker Image for Spring Boot App?

You can open the project from this link. After implementing one endpoint, create a Dockerfile with following content.

FROM eclipse-temurin:17-jdk-alpine
WORKDIR /app
COPY build/libs/*.jar app.jar
EXPOSE 8080 5005
ENTRYPOINT [
"java",
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005",
"-jar",
"app.jar"
]

In order to create Docker image, build the project and execute the following command.

docker build . -t remote-app

I assume you are in the folder where Dockerfile located. In my case, I gave the remote-app name to Docker image.

Connect via IntelliJ IDEA

Before running our Docker image, first create remote debug configurations inside IntelliJ IDEA.

Click Run tab, then select Edit Configurations option. Create a new configuration in the newly opened pop up. IntelliJ IDEA will give default configurations which is enough for our scenario.

If you want to join Docker container which is running outside of your machine, change the Host value to appropriate host. Click OK button.

Now, it is time to run our Docker image.

docker run -p 8080:8080 -p 5005:5005 \ 
--name remote-connection remote-connection:latest

I exposed 2 ports, one will be used as a main port, the other one will be used for debugging purpose.

If your application is started, then you can start remote debugging inside IntelliJ IDEA.

Let’s send a POST request.

curl --location \ 
--request POST 'http://localhost:8080/api/v1/student?firstName=Nicholas&lastName=Jackson'

When you send above request, you are going to see your breakpoint is triggered inside IntelliJ IDEA.

As you can see from the above image, we received first name (Nicholas) and last name (Jackson) values.

The Image You Can Hear :D

Downsides

To summarize, this feature might be beneficial for you, but it comes with its own problems. Exposing a port for your production environment will lead to some security issues.

In addition, if you put a breakpoint inside IDE, it will pause the application until you release it. Let’s say one part of the application doesn’t work, then it doesn’t make sense to debug the app, because other requests will be blocked.

I recommend that do not use it in production until you don’t have any chance. If you have test or dev environment, feel free to use it, but inform your colleagues about this.

Conclusion

We came to the end of this part of Docker Advance Series. You can access the this part’s code from here.

Published in DevOps.dev

Devops.dev is a community of DevOps enthusiasts sharing insight, stories, and the latest development in the field.

Written by Mammad Yahyayev

I am a Software Engineer with 4 years of work experience. I love to share my ideas, knowledge with everybody. Follow me to stay updated on the latest trends.

Responses (1)

What are your thoughts?

At first, we are going to create Docker Image for application, then we will connect via IntelliJ IDEA remote debugger.

This post is a treasure trove of insights—thank you for sharing!

1