Live Remote Debugging | Spring Boot Application Running in Docker Container | JavaTechie

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to java techie with the trending of containerizing applications setting up your local environment is now easier than ever we everyone know how to dockerize your application and run it inside docker container right but it's bit tricky to debug your application which is running inside a docker container in this tutorial i'll walk you through the steps to debug a springboard application which is running inside a docker container with remote debugging feature okay so without any further delay let's get started [Music] so our very first step you need to create a springboard application then we need to dockerize that springboard application to host in our docker container right then we can debug it so to save our time already i created one small springboard application where i am not using any database and all i just created on employee repository and i hardcore few employee object here you can see here and then this is what my employee class id name department and email and if you will go inside the controller class we have the two rest endpoint one will return list of employee based on the department and one will notify to the employee based on the department okay let's say for a developer i just want to notify some announcement so i will just face the list of email id specific to the developer and i can run this logic this is just a sop ln statement but you can execute the exact logic i just added this dummy piece of code to debug it okay so next to dockerize our springboard application first we need to write a docker file but before that let me generate the jar of this docker image debugging application so if you will go to the pom.xml i will generate a jar name with spring hyphen docker.demo that's why i just added this final name tag now let me execute the maven goal i can directly execute maven install okay it will just download the jar to my target folder so it may take few seconds let's wait it to complete yeah so you can see here build is success now if you go inside target folder you will find you'll find a jar with name spring docker demo dot this is where the name we mentioned here okay now next step we need to write a docker file so just right click on the root directory click on file and give the name docker file so if you observe d is the upper case and everything is lowercase just enter it so as part of the docker file first we need to specify the from and we are using openjdk8 right open jdk and i will just specify the version is 8. now next what is the port you want to expose i just want to expose the port 8080 which is my container port and also i just want to expose another port which is eight triple zero with this port eight triple zero i will continue my remote debugging okay then next just add add and give the directory of your jar file so it is inside target and the jar name is spring dockerdemo.jar okay then i will just copy this name and i'll just add it here that's fine then i will also copy the ad and to make the remote debugging i'll just write one ss file or script files which is nothing the sales script so that i can tell to this my docker just enable the debugging for this particular jar okay so for that what i'll do i'll just create a file here you can give any name for now i will just make it entry point dot sh okay but if you are using windows then you can add this extension as a dot b80 which is a batch file just enter it and inside this entry point.ss i'll just add this script here i'm telling to this docker execute this java command to enable my remote debugging that is what we are giving here right jdwp java debugging protocol and these are the address we are giving eight triple zero that is what we also mentioned or exposed from our docker file and inside that we are giving the jar name spring hyphen docker demo dot jar this is our target jar right spring hyphen docker demo jar now i just need to add that entry point dot sh then i will copy it and i'll give it again now next we need to provide the entry point and we'll tell to the docker just execute this command so i'll just add sh and then i'll give this script file to execute when i'll just run this particular docker image okay i'll just add it so that is what we just added the sales script file which is entry point.ss where we just tell to the docker run this particular jar on debug mode and we just added that reference in our docker file now the next step we can create the docker image of our application because when you will create the docker image it will search for the docker file so we have this docker file now go to your terminal so before that first let me start my docker desktop now docker toolbox is not supported if you are using windows or mac operating system you must need to download the docker desktop okay you will find both the version for windows and mac as well you can see once it will start you will find this green symbol and if you go inside images i have these images so i will create image with different name now i'll just go to the terminal i'll type docker images you can see this image right so i'll just give docker i'll just create the image docker build hyphen t then give the image name i will just give the name spring docker debugging or something like that then i'll give the version or you can say it is a tag just add the root directory just enter it it will create a docker image for you it will take few seconds to complete yeah you can see here now if i'll search docker images i can see here right spring docker debugging and tag is 1.0 and five seconds ago we created it next we need to run our docker image so to run the docker image you can fire the command docker ron then you can give the port which is eight zero eight zero which is nothing our container port right and then you can give the another port where you want to debug your docker image so i'll just give the triple zero eight triple zero and eight triple zero now you just need to give the image name so for us the image name is this copy this paste it here and also you need to provide the tag which is 1.0 fine just enter it you can see here listening let me show you listening for transport dt socket address 8 triple zero if you are getting this message while boot up your springboard application then you configured correctly remote debugging okay so you can see here it got started on port 8080 now let's go to the browser we didn't enable the debugging in our application yet okay we have just exposed our docker image with the debugging mode and we specify the port for debugging now if you go to the chrome and if you will type localhost if you will give eight zero eight zero slash employees okay employee yes so let's let me check the end point go inside the main class okay we just need to provide the department now if you will check the repo the department is something called developer okay you can we have the multiple department developer devops manager and hr you can give any name so i'll just go to the browser i'll just give this okay i added wrongly localhost 8080s slash employee slash developer you can see the record right there are three record with the department developer and also if you will try for let me check the debuffs and if you go to the browser and change the department we'll find the two object or two employee object with the department devops right so it means our application successfully running on docker container now we need to enable the debug from our id now just click on this edit configuration you'll find the plus icon here just click on it and search something called remote you can see here remote jvm debug just click on this you can give any name i'll just give docker remote debugging or something like that you can give any name here and make sure this debugger mode should be attached to remote jvm and give the port which you exposed which is eight triple zero and you can see here this command will be auto append based on the jdk version what you are using and the host is localhost and this is your the module just click on apply click on ok now we enable the debug mode so just start your application or this docker image on debug mode you can see here connected to the target bm address which is triple zero now i will just add a breakpoint in my application so that we can see whether the request is coming to this particular line or not in debug mode so i'll just add everywhere let me add it here these are the java 8 code so i already added the plugin java 8 stream debugger so i can visualize all the value i have already uploaded your video how you can debug the java 8 stream api if you are not over about it you can check out my tutorial i will also add the link on video description guys okay now let's hit the api let me minimize this yeah just go to the browser i'll just hit this now you can see the request directly came to the endpoint on the debugging mode if i will take this up you can see the value let's step step into the next line you can see here and see if you added the javad stream debugger plugin on your intellij i am not sure for the eclipse but if you added you can see this particular icon okay trace current stream change just click on this we are getting all the employee repository or employee object from the repo then it is still showing the evaluation and process let us wait for a second yeah it will fetch all the list of employee object then it will filter based on your condition we are giving the department filter as a debuff so there is two object for devops it will face these two object then will just return us then close it move to the next this is what it will just return you i'll just close this okay now if you go to the browser you can see the response here now i'll just give you developer just enter it request came to the endpoint as you enable the breakpoint here now step into the next line if you will evaluate it you can find entire stream then your filter logic you can see it returns all the employee object then it will just filter based on your criteria we are giving the developer department so it filter three object and it returned to you that is that's it it means the debugging is working okay now let's move to the next api to check the debugging so i will just remove the breakpoint let it be because i am not going to hit this end point i'll just copy this and then let me pass this fine go to the chrome then i'll just i'll just add it here notify then department just enter it you can see request came here now let me check whether i added yeah i added the debugger here just step over you can see it came to your repo ok now if you evaluate this it will return you the list of employee then it will filter based on your criteria we provided the department as developer so there is three objects for developer then we just want to gather the email id that's the reason i just used map function here okay as a string so you can see here all the developer all the employee object whose department is developer just give me their email id that is why i used map here and then collect it and return it to me as a list of string that is what it is doing close it if you see this logic that is what the functionality so it means the debugging is working here right so let me pass it so if you will see the return type is void you can't see anything okay so this is how you can enable remote debugging for your docker image which is running inside docker container and frankly this is not the recommended way to debug your docker image it may require sometimes on the day or stage environment but for production environment this is really not recommended you can avoid these steps so i believe these steps is clear for you you can give a try just create a small springboard project and then dockerize it you can find all the source code on the video description and try on your machine and do let me know in comment section if you have any doubts that's all about this particular video guys thanks for watching this video meet you soon with a new concept
Info
Channel: Java Techie
Views: 17,703
Rating: undefined out of 5
Keywords: Docker remote debug, javatechie, docker, remote debugging, remote debug docker container intellij, how to debug docker container intellij, run docker container in debug mode, attach debugger to docker container intellij, docker compose debug intellij
Id: QuBgmaILdWI
Channel Id: undefined
Length: 15min 11sec (911 seconds)
Published: Fri Feb 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.