From the course: Using Docker and .NET Core

Docker tooling in Visual Studio

From the course: Using Docker and .NET Core

Docker tooling in Visual Studio

- All right, welcome back. So in the last video, we talked about kind of what was Docker, a Docker file, and how to kind of build and run those Docker things. And one of the questions I asked was, is there something in Visual Studio that can help us out? - Yes. Okay. - And yes, there is. - Okay, (chuckles) awesome (chuckles) Yeah. - So what are the things that we've got in a Visual Studio as far as tooling in this awesome IDE that can help us out? - So you can create, you can add Docker support to your project which automatically creates an appropriate Docker file for you. You can edit your Docker files, of course, and you can also run your container directly from Visual Studio, build and run your container from Visual Studio, including folder backing support. - That's fantastic. Yeah. - Let's see what that looks like here, so I've got in my editor here just a basic ASP.NET Core web application much like in the last video we showed a console application, this is a very simple "Hello World!" application. I'm assuming I'm going to right click here - Yup. On that project. - Exactly. And kind of look for our tool and we've got Add- - Yes. And you want to click Docker support. - Docker support, all right. Yup. - [Shayne] So let's see what happens here. It's going to ask me which OS I want to target, so in Docker, we have Windows as we were using last time, we were using a Windows console app, here I'm going to choose Linux cause I want to deploy this to the web- - Yeah, absolutely. at some point, I think. All right, so we choose Linux. And it looks like it added a Docker file so I mean, that was pretty fast. So I'm going to choose Docker file and see what that looks like. Well, that looks a little different a little (chuckles) more scary than the last Docker file that we had. Kind of what's going on with all these? It looks like I've got multiple sections of the Docker file that we explained in our last video. - [Lisa] Right, so you see the multiple FROM statements and that means that this is a multi-stage Docker file. - Okay. And what that means is that you can pull a base image, you can do some things to it, and then you can use that intermediate container that you've created to build another container image. - Okay. So this is commonly used because for example you can see here that you are using a container image that contains the dotnet core SDK. Which is great when you're building a container, especially on the Linux where you need to build that... The actual application inside the container. But you might not want all that extra bloat of the SDK for your final production image- - Sure Because you don't need it, and you want that to be really small and lean and fast. So you can see that that very last block that starts with from base as final ends up building a container image that does not have the SDK, it simply has dotnet core in it, and it's got your application and that's it. It's got everything that you need to run and nothing you don't. - So if I'm looking through these multiple layers as you're explaining it, it appears as if I'm labeling this first section as base- - Right. - [Shayne] And then in our last section down here, I'm actually using that as the first set. So I'm not actually going out to another registry to pull another one, I'm using the one that's built as an intermediary. - Exactly. Right. And then using again from published, so if I look back up in my other sections here, I've got build as published- - Exactly. It looks like a building a released version of my web application, and then putting it into this publish layer. And then again, putting it out kind of altogether at the very end. - Exactly. - And then I think, look, entry point here is a little different than the last one we had in our last video. We talked about, we had dotnet run where we just kind of running all of the bits that we moved over, and it looks like here, we're saying.net and then running Docker web DLL. So we're actually running the application as if it was already ready to go. - Exactly. That's the expectation. - Yes. So you had mentioned that we can actually run this right from Visual Studio,- - Yes, that's right. Right? So if I look up, as I'm used to doing in Visual Studio and to our 2019 here, I've got some other options, I can run an IIS Express, which I think we're used to doing all the time- - [Lisa] Yeah, that's local on your machine. - [Shayne] Right, and then we have Docker web which runs in our Kestrel instance locally. And then also, now I have a new option called Docker, right? - [Lisa] Right, so when you add Docker support, that gets added automatically. - [Shayne] Cool, Interesting, so I can just hit play here? - [Lisa] Yes. - [Shayne] And we'll see what that looks like. So I'm seeing down here in our little console here a background task that it's actually doing some things here. Let's see if I put up the output here, and it looks like, wow, that was pretty fast, okay? And I think as long as it's in a browser as we would expect- - Exactly. - [Shayne] And we get our "Hello World!". - [Lisa] Yup. - Here, just like we would look at. Now, I know normally that when I run kind of all my local machine and those other options, my port... so mostly something like 5,001 or something like that, and in this instance I'm getting another port. Now, is this a port on my local machine, or is this something that I'm getting out of my Docker container? - [Lisa] That's mapping to a port inside your Docker container. - Oh, okay, great. Yeah. - Now you mentioned I can set a break point- - Yeah, you absolutely can. Yeah so- - Everything that you can do to debugging locally, essentially you can do when debugging in a container as well. - [Shayne] Okay, so I'm going to actually go over here to... Let's go and find where we can set a break point. So we've got this response, WriteAsync, and let's just see if we can actually hit the break point. So now when I'm running this I'm assuming that I'm running inside of the container, and I have my debugger attached to that container- - Exactly. As well, right? So if I hit a refresh on this, and as expected, - There we go. - That's pretty great. Yup. - Awesome, all right, so if I hit continue. So that's awesome, I got my "Hello World!" as expected, but now that I have my application in a container I'm working on my local machine, how do I get it somewhere? - So Visual Studio has some built in tools that allow you to publish your container image to a variety of different locations. - Oh, that's great. Well, let's look at that in the next video.

Contents