How to Run and Debug Java Inside Docker Containers Using VSCode

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today I'm going to show you how to run your Java project inside Docker container inside Visual Studio code that way you don't even have to have Java installed on your computer let's get started here I have an empty Java project open and the first thing we want to do is go to the bottom left corner and click on the green square with the greater than and less than signs and then click the option to reopen in container it may take a couple of seconds and then we will see a list of different definitions that we can create the configuration file from so we will choose Java and then we can choose the Java version I just pick the default one and and then we can skip the node.js version if you want to install different build tools like Maven or Gradle then you can do that here as well I'm not going to do that then it will ask us if we want to add any additional features we don't need any of that right now so I'm gonna skip that as well and then it may take a few seconds or minutes depending on how hard your laptop or computer is running to to create this remote container and you can see the law of what's Happening by looking sorry in Dev container show log and in the terminal you will see what is happening not that you will understand any of what's happening but at least you can see and at the bottom left corner again you will see that it's opening remote so whenever it's done opening then you know you're good so after it's done in the bottom left corner you will see that opening remote switch to Def container Java and in the file explorer inside Visual Studio code we can see the new DOT def container folder and it will contain the configuration for this Dev environment so you'll see the dovecontainer.json and the docker file and you don't really need to change anything assuming you have selected the configuration that you actually wanted the next thing we want to do is create a new Java project so you can press Ctrl shift and P at the same time if you're on the Mac it would be command shift p and then you can type Java and create Java project check and then we can once again select no build tools and then just click OK for the default workspace and give it a project name I'm just gonna name it test proj it will open a new vs code window but you can close it because we can run and debug code from this container that we already in so if you go inside the test brush folder inside the source and app.java you will see the hello world program and if you click on the debug icon or maybe the play icon if you have not debugged your code yet you can just click it and it will either run your code or debug it and I accidentally clicked it twice so let me cancel one of those just warning it's going to be pretty slow the first time you run it after the first one it shouldn't be as slow anymore and it applies for both running and debugging your code so here once it's done important projects and setting things up you should hit this breakpoint where it prints the hello world line and as you can see it did hit it so now we can either go to the next step which we don't really have anything here or just click continue and it will finish running the program and to show you that it is indeed faster to debug after the first try we can change hello world to hello YouTube and debug it again and as you can see it is considerably faster this time and that's it that's how you run and debug your Java code inside a Docker container inside vs code and while you're waiting for vs code to set up your Dev container go watch a video on how I prepared for my Amazon Interview
Info
Channel: codevev
Views: 5,912
Rating: undefined out of 5
Keywords: docker tutorial, docker environment setup, docker environment, vscode docker remote, vscode docker, vscode docker development, vscode remote development docker, docker made easy, docker in vs code, vs code docker python, docker vscode, docker vscode extension, vscode remote docker container, vscode java docker, java, java environment setup, java setup in vs code, java vscode, java docker, java debug docker, java vscode debug docker, java docker debug vscode, debug java
Id: SpF-MQu35No
Channel Id: undefined
Length: 3min 47sec (227 seconds)
Published: Thu Aug 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.