.NET 8 .πŸš€πŸ”₯: Containerise Web App without Docker file - A Step-by-Step Guide

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello friends thank you for watching this video I am Muhammad and today we're going to be seeing how we can containerize our application without using Docker we're going to be relying on a doet technology that comes with our application in order for us to do so so let's get started what I have here is I have the interface to create a new application so what I'm going to do here is I'm going to create a new one going to call it sample web app and going to change the directory I'm going to keep it as an MVC we can see it's running on C and basically here I have a Docker support for Linux and this is what I want so I'm going to click on create so now that has opened as you can see here I have I have a normal MVC application I have my controllers I have my models I have my Docker file and what I'm doing here I'm just I'm just basically utilizing the out that I'm using the template that is automatically provided I'm not doing any custom work and this will also work for we API I just thought the MVC will be a bit of a change of Base so now that we have this here what I want to do is I want to run this so we can make sure that everything is running as it should be and now we can see my application is running I'm going to open my web browser and now we can see that my application is running and I can go from page to page and everything is running as it should be okay perfect so now let's go back to my code and basically what I'm going to doing I'm going to stop running this I'm going to put my locker file into the root directory in order for it to run if I open my Docker file we can see it's running on it's exposing two ports Port 880 and Port 881 for https and we can see it's doing the standard Docker items in order for it to containerize it so I moved my Docker file from my to my root directory so now it's available on my root directory I'm going to remove this we don't really need it okay perfect so now I have my Docker file here and what I want to do in order for for me to first of all run it within Docker I'm just going to go to my terminal so now what I want to do I want to run through Docker so I'm going to put LS check I'm on the right directory then I'm going to put Docker build and I'm going to give it a tag sample app I'm going to version 1.0 so now that my application is building this should take a few seconds to complete and now it has been completed successfully I can do I can actually run it now so I can put Docker run specify the port and from going to connect to it from port 8082 to port 8080 and it's going to be called sample app version 1.0 so now we can see that application is running if I go back to my web browser and I go to Port 8082 we can see that my application is running perfectly inside my Docker image okay great so I'm going to stop this right now and this is the last time we're going to be we're going to be interacting with Docker perfect so what I want to do right now is I want to actually utilize a different command in order for me to publish this into into Docker and create a containerized version so I'm going to for comparison sake I'm going to leave this here but what I'm going to do right now is I'm going to go into my application to my sle web app if I click on LS we can see that I'm inside that application I'm going to clear this and I'm going to utilize the following command in order for me to publish my application the command is going to be like nut again this is we're going to be relying on publishing it into our Docker we're going to create a container image nut publish and I'm going to specify something here called dasp and I'm going to put publish profile equal to default contain so if you take a look at this I have not specified here anything regarding Docker I did even the directory that I'm running this from is completely different where my Docker file is so if I run this right now now we can see an MS build is running we can see that my application has already been published and we can see I'm building an image and that image is called sample web app and we can see it's been deployed to Docker so if I open now my Docker registry you can see here that I have my sample web app created for seconds ago and basically it is running and all of that if you remember even from the first one we have utilized a different tag which is sample app and this is sample web app and this is here we can see that a new image has been directly created from my code using the net publish command Direct L into my Docker and this is basically one of the newest feature that has introduced is remove the direct dependency on Docker in order for me to have a containerized image so you might think okay great now I have this running how can I run it and actually see it's the same thing so let's run it so I'm going to put Docker run I'm going to specify my port so I'm going to put Port 8083 connect to port 8080 and I'm going to use the same one same image name sample web app now we can see it's running on port 8080 and I specified Port 8083 so if I go back to my web browser and I change this from Port 882 to Port 8883 we can see it's still running and I can see that here that I'm able to utilize it normally okay perfect so now that I'm able to do so and This Is Amazing by the way this this new functionality is really good so once I have done this now let's see how we can actually customize it because you make into yourself okay there's a lot of customization that I would like to do but I cannot really do it through this command and you're right in order for us to do this customization similar to what we have with Docker what we want to do is we want to go to our CS Pro so I'm going to quit edit CS Pro here and first of all we don't really need this anymore because we are not utilizing Docker and what I want to do here so inside my publish command I had to specify here my publish profile so what happened if I don't really want to publish this every single time what I can do inside my property group I can specify my publish profile and I can then specify it's going to be default container so now that I have this I can actually just simply do not publish without me specifying anything else and it will automatically publish my application into the new into Docker so we can see here 2 seconds ago we got a new image that has been published okay perfect so now that this is running and now I know how to do this let's see how we can actually add more customization to this publishing using my CS Pro so first the customization that I want to add if we go back to my Docker file we can see here on top of it I'm actually specifying my base image so here in my base image I'm utilizing is asp.net version 8 from Microsoft Etc here what happen if I want to actually specify manually which version I want and this is easily can be done through here so if I want to specify the base image for my net publish what I can do is I can go and add the following I can add a container base image and then I'm just going to copy the same one as here and now again I'm going to do another publish that's a clear do not publish and we can see here that it's publishing it's using the latest image that I just specified here and and it published it for me perfect so what happened right now if I want to deploy to a different container registry So currently everything that I'm creating as my Docker images is being directed into my local container registry what happen if I want to direct this into a different container registry like uh as container registry or dockerhub in order for me to do that going going be also pretty straightforward what I can do I can put container registry and then from here I can specify my container registry so I can say muhammad. Docker hub.com and I can say for example anything like this so here for example this is a custom. container registry so when I run not publish it will work but currently this does not exist so it will not work but basically this is how I can specify my container registry let me commend this out so something other than that if we if we pay attention to do not publish here and let's take a look at the last image so we can see here that it's in always with the latest tag what happen if I want to specify my own tag and this is and this is very easy to do so after here what I can do is I can specify my container image tag and I can specify let's say I want tags version 1.1 and I want latest as well so if I save this I go back here I putet publish let's clear this up so it's more visible I put net publish and we can see it's publishing and now we can see here that I have version 1.1 and latest if I go back to dockerhub we can see now I have two tags one for version 1.1 and one for latest okay perfect so what happened if I want to actually change the port so here we can see that within Docker I exposed the ports that I want and through that I was able to connect to it so in order for me to do that through here what I can do is let me minimize this I'm going to create a new item group and I want to add the following so it's going to be container or I'm going to specify my include to which container to which Port I wanted to listen I can put Port 80 89 for example and I'm going to specify the type to TCP and that's it and this how for example I can actually expose the port that I want and it will automatically be able to listen to so again Within Docker here if I want to pass any arguments I need to utilize it through the docker command line when I'm building it and running it so how can I actually pass arguments here again it's pretty straightforward it needs to be container environment variable can say include I can say here is for example be connection string and I can specify the value equal app. DB for and this here for example when I run this it will automatically be injected into my container and it will automatically run so we can see here that this is a very very very powerful tool in order for me to decouple directly from Docker in order for me to containerize my application and this is a big push from Microsoft into having Cloud native application but with this there is some caveat that we need to take into consideration like for example the customizability of this having the capability of changing stuff on the Fly similar to what Docker commands give us having the ability to alter some of this configuration it's going to be is not there yet but it's getting there and something which is really cool about this is right now what as you can see everything is running through Docker so if you take a look here here everything is being deployed through dock but the nice thing about it if what happen if I close my Docker and I have podman running right now on my machine I'm going to run the same commands so I'm going to create this again and I'm going to put net publish and I'm going to let's wait yeah I'm going to run it right now and now this is running the main difference is right now that instead of relying on Docker the application is smart enough and the SDK is smart enough in order for it to realize that botman is there and is published it to podman so now if I open my pman dashboard I'm able to see that my sample web app this has been created right now is on version 1.1 and it's going to be on the latest so if I want to update for example here my tag to version let's say 2.1 I can directly publish it and now if I go back to my podman let's give it a few seconds and we can see here if I refresh this we can see here I have version 2.1 directly available for me through podman and this is going to be the main powerful item behind this is this is basically decoupling a lot of stuff from Docker and basic giving us the capabilities of editing and content our application the way we want to so within this video we have seen how we can actually containerize our application without Locker I hope this video was helpful if you have any questions please make sure you put them in the comments down below if you'd like to support me please consider supporting me on patreon or buying me a coffee with that said thank you very much for watching and have a great day
Info
Channel: Mohamad Lawand
Views: 1,420
Rating: undefined out of 5
Keywords: .net, api, beginner guide, step by step, csharp, c#, dotnet, dependency injection, code with me, ef core, entity framework core, rest api, crud, dotnet data, dotnet services, .net core, asp.net core, docker compose, docker explained, dotnet docker, dotnet dockerfile, dotnet docker tutorial, dotnet 8, .net 8, Containerization, Docker Tutorial, Docker Integration, Docker Containers, DevOps Tools, Coding Tutorial, podman, containers explained, dotnet podman
Id: FzWgM8Iot1A
Channel Id: undefined
Length: 9min 45sec (585 seconds)
Published: Thu Mar 14 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.