Transcript from the "Debugging Containers" Lesson
>> Burke Holland: All right, so we've composed but we have other files in this project as well, particularly one of interest is this docker debug compose. What does this file do? Well, oftentimes or sometimes in your application, you'll get to a scenario where you've built the container, and then you gotta run it and it doesn't work.
[00:00:21] Or the application runs but it fails, and you don't know why. Now, this is a problem because your application is running in the container. And so if you were to debug your application outside of the container, you're not in the container anymore. Now you've changed environments, and now your problem might go away.
[00:00:37] Okay, if that happens, there is a debug compose that you can use, along with the Visual Studio Code debugger to make this work. So the compose file we don't need to do anything with, but we do need to add a debug configuration. This should look a little bit familiar.
[00:00:58] So we'll do start, and then it's going to add the launch config to our folder. And then we will say Docker: Node.js, because that's what we're doing. And then it wants to know where is your app. Remember that path inside of our container, that's this value. And here is our launch config.
[00:01:23] Now, I need to make sure that I've got this just right here. Got the launch config, I should be just fine. And now what I'm going to do is, I'm going to save this and I'm going to compose up, select start, but this time I'm gonna pick the compose debug, okay?
>> Burke Holland: And our container is running, what we need to do is kill it. So let's just do that, come over here. So if we kill this one here, let's stop this one, here we go, and let's compose debug again.
>> Burke Holland: And hopefully, that'll do it. One thing you should know about the Docker extension is that every time you run a command, it opens a new instance of the terminal.
[00:02:16] So there's a lot of them. If you wanna just rerun the last command, just hit the up arrow in your terminal, and it will autofill. Cuz all this is, is a UI on top of the Docker CLI. So you do all this stuff with the Docker CLI, you just have to know all the CLI commands, it's just easier to do it visually.
[00:02:34] I did talk to the team about this. There are some technical limitations about why this is the way that it is. But for now, do some cleanup every now and again, clean them all out. All right, so we've got our container running, and now we want to attach the debugger.
[00:02:48] So we've got Attach to Node, which is our debug configuration. So I'm gonna do that. And now, if we go over to our container, let's put a break point here. And come over to our container. And let's see local host 3000. There's our application, let's change the color.
[00:03:12] And now we're debugging inside the Docker container. All right, so this is a very, very powerful option that you have for when your container doesn't work, your code is failing in your container and you don't know why. In order to flatline you can just use the Docker debug and go add breakpoints like you normally would.
[00:03:33] So now we're hitting the break point, we're actually in production now. You want to be really careful with this because, if you've got a break point, then the application is halted on the break point, and so you probably don't wanna do that, but a better option would be what?
>> Burke Holland: What could we do in production that will not the disruptive for our users?
>> Speaker 2: Log out something.
>> Burke Holland: Sorry.
>> Speaker 2: Log out.
>> Burke Holland: You can log something out, and how do we do that? Do you remember what it's called?
>> Speaker 3: Log point.
>> Burke Holland: Log points, that's right.
[00:04:02] So we could add a log point and say, look at record maybe we want to know, maybe this is failing and we don't know why, so we wanna look at it.
>> Burke Holland: Okay, and now we can see the value. So this is really powerful. If your provider supports this, of course app service does, but if your provider implements this and he has an extension for VS Code, you can log out from applications that are in production, which is pretty nice, troubleshoot on the fly.
[00:04:44] All right, man, we've done some amazing stuff today. Let's take our Docker knowledge of which we have a ton now. I don't think there's anything else I wanted to cover in this section. And I hope that was it. So that was your breakneck intro to Docker.