Welcome to lab 13. And in this lab, we will focus on micro services using Docker. And this whole demonstration we will demonstrate on the as your environment. Now, Docker implements something called as the micro services architecture style. So before we get into anything, let us first try to understand why has microservices come into existence? When developers create applications most of the applications are monolithic in nature.
In other words, they create them as one big unit. For example, let us say you have an RFP package univariant we have accounting we have inventory, we have payroll and so on. But when developers will structure this project, you know, they will create one single database for everything, they will have one source code. So definitely the source code will have layers like business logic data access layer, UI layer and so on. But in but at the end of the day, logic They are one single unit. In other words, you know, when I change in inventory, it will probably go and change accounting projects as well and when I change in accounting, it would be making changes into inventory database and so on right.
Now, for many projects, you know, this is still a work architecture, this is okay to have right. But when you talk about big project size with a lot of team members working on it, so, some team members would be working on accounting, some team members will be working on inventory must be some team members will be working on fine tuning of the database and so on. So, you know, when you have big, big team size, you know, you want to do probably parallel development. Parallel development means, you know, you will have some developers working on accounting, but due to that inventory should not get affected because logically they are different modules altogether, right. When somebody is going into fine tuning database of accounting, I don't want that inventory table should be updated. But you do this more Architecture, you know, this becomes really a big bottleneck.
Second, you know, when you talk about big companies, you have people working on different technology stack, you have some people who are adopted SQL stack, you know, then you can have people who are Java, Oracle stack, or some people can be my SQL stack to ensure maximum productivity and proper usage of your development team, you would probably build a single project in multi-platform. So must be the accounting is built using PHP, my SQL and then the inventory is built using Java Oracle, or must be the payroll system is used using using dotnet and SQL Server stack, right? So, you know, the one of the project problems with the monolith architecture is that parallel development is difficult. Parallel deployment is difficult. So, for example, when I change in inventory, I want to just deploy the inventory modules. But then, because it's a monolith architecture, I end up deploying everything.
And the last point is multi platform development in bigger companies. You know, you have mixed bag of developers and sometimes you'd like the developers do not really change their technology stack very easily. So probably you'd like to reuse the the current technology stack whatever the developers have, and create a project. So there are three big issues of monolith architecture, parallel development, parallel deployment, and multi platform development. So to address those three issues, we have the microservices architecture study. In microservices architecture style, what you do is that you structure your project as different physical decoupled entities.
So probably you can go and you can create an accounting project using dotnet. Visual Studio is SQL Server. And this accounting project will have its own accounting database, it will have its own way of doing things. The developers who work on accounting, you know, they won't be focused on accounting. And then you can have inventory and inventory will have its own In its own database, it can probably have some other technology like Java and Apache and probably yes, it can also be in dotnet if you want it right. But again, the inventory project will be different it will be a different physical decoupled entity.
So with this approach now what will happen is the developers who are working on accounting, you know, they will only change the accounting modules, they will only deploy the accounting modules because it's a very different physical entity, and developers who are working on inventory, they don't have to bother about accounting. So with this now, you can have parallel development and also you can deploy them separately and parallely. So, when I make change in inventory, I have to only deploy the inventory modules it will not go and change the accounting modules. Definitely in a when the accounting and inventory have to talk with each other we can have some kind of rest HTTP call or must be a swap call or something in between right. So with the microservices architecture, the project structure should be different physical decoupled entities in terms of The source code in terms of the database in terms of everything, right.
But now, seven done this right? One of the biggest problem with microservices architecture is not about creating the project, it is about deploying it. So if you create, let's say, let's say if you have five, six modules, right? And if you want to go and put all these five, six modules in production, then how do you go about it? When you go and create when you have five, six physical machines, right? So basically, you will say, Okay, let's deploy accounting.
Let's just deploy inventory there in the other machine, and then let's deploy some things out there, right. So the problem here is not about creating the project. The problem here is about deploying them into production. So let's discuss the deployment part now. So with projects, having what we call multi technology and different physical units, right. Let's talk about the first week of deployment.
Let's Say that you want to go and deploy deploy them and different physical physical machines. It won't be cost effective right, we will be billed extra for the hardware, we will be paying for the software licenses of the per machine and adding to it the huge deployment effort, you know, where you have to procure a physical machine, then install the operating system on it, and then install your application, right. So definitely different different physical machines for different different modules is not feasible. The other way, what you can think about is you can think about virtualization. So in virtualization, what you can do is, so you have an infrastructure on that you have your operating system, and you can use some virtualization techniques like what we call VMware or hypervisor. And in that you can say okay, now let me go and create a Linux or os os virtual machine, in which I will go and deploy must be inventory, which has Java, Apache Oracle and its own libraries and inventory runs in the Linux operating system.
And then again by using virtualization you will go and probably create a different instance of operating system which is a Windows right. And in that you can have accounting you will employ evil, you will put dotnet is SQL Server and so on and its own libraries. So one way probably if you want to reuse the same hardware, what you can do is you can use virtualization techniques, and you can create multiple operating system instances and they will both they will all talk with each other in you know, through the, through the HTTP calls. But again, the problem here is definitely This is time consuming in terms of deployment. Think about that. If you have one more module, then you have to again go and create one more virtual machine you have to do the necessary installation.
It is first thing it is time consuming. Second, you know, you're you're creating multiple instances of the operating system, which you really don't want. What you really want is, you want multiple instances of the application And not really have the operating system. So this is again becoming very heavy on your hardware. Right. And that's where we have the container based approach.
So, in container based approach, you know, rather than creating different physical operating system instances, you know, you can do something like this, you can create containers. So here is your infrastructure. And then you have your host operating system, which can be Linux or whatever, right. And then you will use some kind of container technology like Docker, or you know, whatever technology you wish. So by using Docker now, what you can do is you can create a container, which has only the libraries related to Java, Apache Oracle and the Linux namespaces or the workspaces I will say, the Linux kernels you know, which can just run your Java application. And then you can go again go and create one more Docker image right, or a container image, which is Windows one and when we can have dotnet is in SQL Server.
So by using this Continue to use technology like Docker. What it does is you know rather than create a complete rather than creating a complete replica of the OS what it does is it makes use of the kernel namespaces to provide an isolated workspace called us container. So, rather than replicating the whole OS you know what it does is it actually you know, uses the kernel OS and tries to share the kernel noise. So, this becomes quite effective right. So, what we will do in this whole video is now we will go and we will demonstrate the following we will go and we will create an application using MVC five and one application using dotnet core that is MVC core. And we will deploy both this application inside Docker in Windows operating system and we will create two instances.
So, one instance is running your old MVC five application dotnet framework rather applicable our other instances running dotnet core, the new one MVC core. So, let us go ahead and do this demo. So you can see over on the screen I have created something called as the Docker demo and in the solution Docker demo I have created two projects one is ASP dotnet core and the other one is ASP NET MVC five in case you know if you're new to ASP dotnet core or to MVC I would suggest to go I would suggest you to watch my tutorials you know which has which covers you know learn MVC core and learn MVC five as well. But you know, just quickly ASP dotnet core is a cross platform implementation wherein you know, it can run on Linux it can run on Windows and other operating system while MVC five you know, only runs on Windows.
So, this MVC five is built by the old dotnet framework when you say old dotnet framework means dotnet four point x 4.74 point 7.1 or 4.5, you know, so this is the old dotnet framework while this ASP dotnet core is actually using the dotnet NET Core 3.0, which is cross platform. But the point here is that I want to go ahead and have one machine and in that one machine, I want to create two Docker instances. Or I can say two containers, one which runs ASP, dotnet core, and another one which runs MVC five. So the first thing is, you know, in order to deploy both of these projects, you have to create something called as the Docker file. This Docker file has the necessary images, or the necessary things you know, which is needed by our application to run. So what I'm going to do here is I'm going to go and create so that we add a new file here.
And let's name it as Docker file, right without any extension it should be just be Docker file. So I'm going to say new item. Well, well, you know, this We just have to say Docker five. Oh, Windows does not allow you to create one. So I'm going to go ahead and use a notepad and I'm going to go and create a Docker file must be, can I go and first add the other way what I can do is I can go and I can add a text file, right? We add a text file and I will rename this as dockerfile.
Right so you can see here, I've created a Docker file, right but without an extension, you know, you should not put here dot txt or dot docx or anything it is just a Docker file, right? And if you go and if you see it in the file explorer, you will you will see this dockerfile like this, and without an extension, so in this Docker file, you will actually go and put whatever you need, you know, to run MVC five, in the same way I'm going to go and put a Docker file inside ASP dotnet core as well, right? And in this you know, I will have the necessary things you know, which are needed to run ASP dotnet code. So let's first start with MVC five, right? And let's try to understand the syntax and what is written in Docker file. So you can see here in the Docker file, I have put two lines of syntaxes the first one says, you know, from Microsoft, ASP, Microsoft slash ASP.
Net. So now what happens by using the from syntax out here is it actually goes ahead and gets the image of Microsoft ASP. NET, there's Microsoft ASP. NET is already made image which is, which is put out that and, you know, onto the Docker site, and it actually goes ahead and gets this image and installs it inside your Docker containers, right. So we can see that he is not installing the whole whole Windows operating system. And then what we can do is we can go ahead and for MVC five, we can publish our DLL and from the, what he called the Publish folder so for example, now, let me do like this, let me say build.
And let me publish ASP dotnet MVC five. So I'm going to go and say publish it on the folder. So from the bin slash release folder, so you can see here I am trying to publish it, right? That is published. So basically, now this you know, this publishing has happened into this folder out here. So you can see here, that's the folder where it is published in a publish bin.
You know, over here, right? So basically what this Docker file is saying, from the bin slash release. That means From the bins slash release from the bin slash, release, slash publish from the bin slash release as published, take up all the DLLs and put it on a net ww root. If you want, you can go ahead and create an ASP dotnet virtual directory as well and copy on that right. So again, you know, for that you need to, you need to go and hunt for syntaxes which can create the virtual directory, right? So you can think about this Docker file is is where all the action happens.
So you give this Docker file and Docker just create some container by using by by looking at the Docker file. Also, one more important file needs to be created which is the ignore file. Because you know, it's possible that you know, he will try to copy other folders as well. For example, in the Publish folder I probably Don't want him to copy any kind of bin or how do you say OBJ folders if there are there, right. So so in case you know, in case in the Publish folder if there are, for example, in the Publish folder, you can see that this is a bin folder, but there are some folders in which I don't want him to copy. I don't want him to copy this OBJ folder out here, right?
So I can go and I can create a Docker ignore file. So you can see a dot doc ignore file. So I'm going to go and create a Docker ignore file. Now, again, the problem. Windows operating system does not take any kind of dot file name directly, right. So I'm going to go and copy this Docker file.
I'll rename this to dot doc. Ignore, right. So you can see a dot docx ignore look at the look at the worry. Call the file naming convention. I also have notes out here you know, which I'm copy pasting. So you can see this is dot dot ignore and in this dot dot ignore file, I only have the files you know, which will not participate into, you know, while publishing Okay, so that we need two files at least one is a Docker file in which I know which has all the necessary ingredients you know, to run your application.
And then we have the dot doc ignore file which says that you know, which of the files has to be ignored, right. So, you can see that this is the ASP dotnet MVC five, which I have here, in the same way, let us look into ASP dotnet core. So first thing for ASP dotnet core, I need the dot dot ignore file so I want him to ignore that and we need to go and put here the Docker file contents rights. Now, the ASP dotnet core is a different kind of beast over there you know we have a lot of command line, ci commands of dotnet core in which we can use to Publish to do a lot of things right. So let's look at the how the dot Docker file looks of MVC go. So I'm going to go and copy paste this some lines of syntax out here and I will try to explain you what the syntax is all about.
So you can see it, I have copied some 1516 lines of code. And let's try to understand it. So, the first thing which you need to understand when you are looking at the dotnet core Docker file is you need to understand that there are some CLR commands in dotnet core which can compile, which can run your complete project so you can see it I'm going to go to the command here, and I will go to the project. So this is where the project is. So I can go and I can say dotnet restore. What this dotnet restore command does is it actually goes ahead and brings all the dependencies.
So you can see here, this dotnet restore command is going to the ch proj file and Get all the necessary dependencies dependencies of dotnet core via using nugget, right. If you want to go ahead and do a publish, you can say dotnet publish, this will actually go and publish the complete project with a complete full build and release into the Publish folder, right. And then you can say dotnet run, you know, to run your application. So dotnet has, you know, lots of commands, the new dotnet core has a lot of commands, you know, to run to publish, to restore, to compile, and so on, right? So if you see in this Docker file out here, some of the commands like run dotnet restore, this is a dotnet command, run dotnet publish, this is a dotnet publish command, right? So whenever you see a run syntax, you know, in a Docker file, it means that he's trying to run something from the command line, right?
So first thing you know, in order to go and run this ASP, dotnet core, you know, what we can do is Like for MVC five, what I did is actually I, you know, I said that I will publish it, you know, on my development machine and over there, it's just a copying part, right? But here in MVC core, you can go one step ahead, you can see that, okay, not only publishing not only body call copying, I can also go and build it inside the Docker image, right. So you can see this first section out here is the build part. Or I can see these first two sections out here is the build part. And the next part next section section out here is the copying part of the compiled folder. So first thing from ASP dotnet.
From Microsoft dotnet. Core SDK, the SDK is for built, right. So you can see the first thing I'm seeing that go ahead and get 3.1 as the build environment. Remember, at this moment, my ASP dotnet code is running on 3.0. But 3.1 is still fine. So I have just taken a bit of higher version out here.
So this SDK is to build while the dotnet 3.1 is to run the application. Remember dotnet core has two setups, you know, one is to do the development. And the other one is if you want to go to production, you need the runtime. So you can see, in the from syntax, I'm getting two things. One is to build, right? And the other setup is to run the runtime.
So this one is to build. So first thing. Now, if you see at this moment, this ASP dotnet core is my current directory, right? So I will say that, Okay, first go ahead and get this image from online. And the second one, I'm saying, Go to ASP dotnet core folder. So that means into this folder out here, right?
So this is like saying change directory to ASP dotnet core, right? So you can think about this syntax. The syntax out here says, change directory or make your current directory Make your current directory as is be dotnet code. When I say your current directory as ASP dotnet core, well, let's make our current directory as Docker demo. I can it should be Docker demo, you can look at it. Look at here, this is ASP dotnet core.
So your current directory should actually be the solution file. Okay, so it's actually it has to be, you know the solution file. So I'm going to go and say, Docker demo. So wherever is the solution file and guys, so I'm going to go and say here my working directory is Docker demo. So wherever is your solution file, right. The next thing is I am saying that copy the CH Flash file and the SLN file, right.
So copy this the CH Flash file and the SLN file into the current directory. So you copy the sheet Plus file from this directory. That means from ASP dotnet core ASP. NET Core. So go inside the SP dotnet core. So you are in Docker demo, you go inside the SP dotnet core, and you copy this solution file so we have the solution file that gets copied to the current directory which is Docker demo.
Right? And then you copy it out here and you run dotnet restore, right you run dotnet restore, okay. Once you run dotnet restore, you know then go ahead and copy the other things as well. So basically you want to go and copy everything else as well. Right into your current directory right So this is just a copying part guys, you know, you can if you want to connect it this in taxes, but I've just kept them no in case a lot of time, you know, people have a different directory for build, right? So copy everything else because you also need the other things for example, the bin folder and you know the source code, right?
And then run dotnet publish, once you run dotnet publish, what it does is it actually goes ahead and creates a publish folder and it copies everything out there, right. And then now you can see here, okay, so from now, the next step is once you have done the, what he called the nugget, so this is actually going and this is getting all dependencies, right. And this is actually publishing and building the project building release. And then after that, you need to get the runtime because without the runtime you won't be able to run your MVC core project, right? So I'm saying that you know, Make your current working directory as ASP dotnet code Docker demo, right? And copy you can see I've changed my directory, right?
Sorry. I mean, Docker demo slash this. And then because ASP dotnet core is inside Docker demo, please understand. And then from ASP dotnet publish out folder, this out folder is normally the output folder, take this DLL and copy it, you know, to the build environment. And the entry point is ASP dotnet core DLL. That's the entry point to start your project.
So you can see here, you know this, you know, this complete dockerfile you know defines how the build will take place. How Publish will take place and how things will run. Remember that the dockerfile at this moment, which I've created, I've created as per my understanding, like, for example, some of the developers will say no, like, I am not going to go and do the build on the production environment. So must be in that case, this complete, all the steps actually all go off, and only what remains is the last one. Right? So you can always go ahead and, you know, customize this as you want it, for example, if you remember, our MVC five was a very small file, because even even the build environment, the build environment, I actually excluded it, right.
But in case if I want to build environment here, then probably I'll be using the MS build command and so on the point why I've showed here, the build environment as well. I want to just show you the power of Docker file, right. So you can see here, I have now two projects, right. One is the ASP dotnet core, you know, which actually is not only built also you know, it's it's running all through the Docker file. And then I had the MVC five innovate in the build takes place in the development environment and what is the Publish happens in the Docker file right? But whatever it is at the end of the day you need these images from Microsoft ASP dotnet from Microsoft dotnet core right?
In case you have SQL Server then please note then you will have a different kind of a Docker file you will also say okay, get me the SQL Server and time run the SQL Server and time on you know the Windows Authentication mode or into the username password mode and so on. So you need to your Docker file actually can become quite complex Right. Right. But But at this moment, you know this for the simple two projects, I think the dockerfile are more than enough and do not forget you need to have the dot dot doc ignore file right. So I think we are all well set you know from the development perspective. Now let us go to a car and let us use of Windows Server, let us install Docker and let us try to create two instances right so So you can see that I'm going to Azir out here and I'm going to go and create a virtual machine.
Now please note that, you know, whatever demo I'm showing here, I'm using as your because I can go ahead, I can, you know, create a Windows Server right out there, I can go and install Docker and then I can just close it off, right? Because at this moment, you know, in my local machine, I have the Windows Home Edition. Please understand that if you are installing Docker, avoid, avoid the windows 10 Home Edition. If you have a Windows 10 Home Edition, probably you can do some hacks and you can try to do it. But I think you know, at some point of time, it's going to fail right? So there are two important things in order that you know Docker should run the first thing is that you should have Windows 10 Professional Edition or Windows 10 Server Edition, you know such kind of thing right windows 10.
Home own do because what we need for Docker is we need the virtualization to be enabled. So, if the BIOS virtualization is not enabled, then it is very difficult to run Docker, right? And windows 10 home actually does not allow it right. So the first thing is I would suggest if you want to do this demo in your local PC, please have a Windows proper Server Edition or a Professional Edition right? So I'm going to go here I'm going to go and use the virtual machine from as your as I've again said, you can do this locally as well I'm just using as your so that I don't have to. I don't want to want to get into headache of having a proper server license and so on.
Right? So I'm gonna go and say okay, let's create a resource group here. Rest one. Oh, it's already there. Rest. Rest Docker.
So this is this resource is where I would go and learn Docker. So this Docker virtual machine name, we can just say Docker VM Let's create this in the US Central light. Remember that US Central I always find it to be cheaper for various reason. And this is where the actual action is we need Windows Server. So what I'm going to do is you know just to be safe enough, I will take the Windows Server Edition you can see of it, we don't have the windows 10 Home Edition here. But in case in your computer, if a Windows 10 Home Edition, just leave it this demo, you can watch it but don't try to attempt on Windows 10.
So at least you need a Professional Edition. But at this moment to be safe enough I would go and take the Server Edition must be I can take the Windows Server 2019 data center edition, right to be just to be safe enough. Let me keep this at this moment as it is. I will not change the size. And let's give a username out here. username and password.
Word for the machine. And other things are all fine review and create. So inside this virtual machine, I will go and I will install Docker, right. So I'm going to go and install Docker we can go and you can change the pricing of the VMs you can see it is telling me that you will be billed seven rupees per hour, but if you want you can go and change it at this moment I won't, because I will ensure that I delete my virtual machine once I am done with the demo, right. So that it is it is creating a virtual machine. And once my virtual machine gets created, the next step would be to go ahead and download this Docker setup from the from the docker.com right and install it inside the virtual machine.
So that's the next step. So you can see virtual machine is getting created. Let's let's give some For it right. Once the virtual machines are created, it should be shown right here in this directory. So that you can see now the virtual machine has been created. So let's go to Docker VM and let us try to connect.
So I would go and use the RDP file to connect to the virtual machine. So there it is. You can see that I'm connecting. And then I will install Docker into this onto this server out here, right. Remote Access is not enabled. Didn't we have Just check that his public IP address assigned to it Why?
So guys, let me fix this and then I will restart my recording. For that it is now I have a public IP address previously I had a private IP address that was a problem looks like it takes some time to get that public IP address that it is. Okay, I can continue working on now. So that it is I'm getting inside the computer once I'm inside the computer, I will go to the browser. And remember that all the as your virtual machines do have an internet connection and what it is just creating a profile so that I am on the website of Docker. So you can see I am now inside this virtual machine, I went to the Docker website, also I have signed up, you need to sign up, you know, in order to get, you know, the Docker thing.
So you can see everything is out here. Also, like, you know, when you talk about Azure as your virtual machines, you know, they have a lot of things and a lot of security enabled. So you can see here, when I tried to use this Internet Explorer from downloading, it was creating problems. I did enable the file download, it was really a issue. So what I did is I just installed Chrome. And chrome allows me to do a lot of things right.
So please, please note that when you're actually inside an Azure as your virtual machine, there are a lot of restrictions. You need to go and disable it or else you won't be able to download the Docker setup, right. So I'm done with it. I have I have enabled all the downloads out here so you can see it. I'm trying To download the Docker setup for Windows you can see there are two setups. One is the Docker desktop for Windows the another one is the desktop Docker for Mac.
So you can see it is installing down below here downloading down below. And after some time I should be able to go and start my installation. So there it is. So refresh. Okay. Come on.
Okay, there it is. So we have the Docker desktop installer. Now let's go ahead and run it. And let us see that you know what, what things we need to do. So in Installing the Docker setup. Okay, downloading packages.
So let it happen. So you can see now he has popped up option yours said saying that Do you want a shortcut in the desktop? Yes, let's have a shortcut in the desktop. Second is saying that do you want to use Linux container? Or do you want to use a Windows container? What it means is that at the end of the day, you know when Docker runs, you know it says that you want to run it as a Windows container.
So do you do you want to really have a Windows container? Or do you want to have you know a Linux container so at this moment, I will just say windows containers because I want to run my MVC five application for which I need windows container right? Must be MVC core, we can have Linux as well. And you can see he can see that he's he's saying that this can be changed after the installation as well. So but at this moment, let me select Windows container. There are lots of demos out there which shows the Linux containers.
So I'm going to go and demo it out using the windows container. So I'll just say okay, there it is, it is unpacking the feis. And let's see that what more things it pops up. And you know till then you know the downloading continues you know let us go to our C drive and let us create a folder here one for MVC five, right so let me create a folder here for MVC five. And inside this you know, let us paste our published output folder here. So we're going to go and create one for MVC five, and must be another for MVC code, right?
So until the Docker container is installing at the background, let us do all our homeworks out here. Right so that is MVC five. So let me go back to my Visual Studio, right. And first thing is let's go to I think we published our DLLs right so like Through MVC five first. So build publish. So this is where our deals were published, right?
So the first thing is we need to copy this publish folder. So this ASP NET MVC five. So what is this copy the, the bin folder, the bin publish folder right online. So I would go and just copy this right over here. That's the first part. The second part, we also need the Docker file and the Docker ignore file.
Remember without this we won't be able to create a container because both of these guys have the you know all the necessary syntaxes you know to create the container so I'm going to go and paste that also here so badly Ah, looks like Looks like one do one thing can be copied at a time. One hour. Really? That's a big time. Right? So let's let's give it some time.
And let me see out here, okay? Oh, you must log out of the windows to complete the installation Fine. Let's so guys everything's happening live. So it's possible that I can make mistakes. So we'll do the copying later on. You can see that I've got a message out here saying that please log out you know, so that the installation can be complete.
So I'm going to go and close and log out and sign in again. And let's see, we can continue with our Docker installation. So oh I need to again go back to the portal of as yours. So there it is. I have signed in again and you can see down below Can you see in the down system tray below. It is saying Docker desktop Stop is starting, right.
And you can see this small icon out here. Remember that the Docker desktop the Docker icon is very interesting, you can see that there is a ship. And then there are containers inside it right? So basically, the logo actually sends out the same signal. This is a container based kind of kind of a software, right? So that is the Docker is that running.
And you can see that you can also switch to Linux container if you want, right. So it looks like our Docker is running out here. You know, it's all their Hyper V containers are not enabled Hyper V is not enabled. That's great. Yes. I want to enable Hyper V. Remember I said for Docker, one of the important thing is that virtualization should be enabled.
So I'm going to go and say, Oh, yes, why not say OK, it will restart the computer. It will enable my virtualization, right? So I just said okay for it. Let restart himself or I will need to do it. So he has enabled it looks like I will need to restart it. Okay so let's get started right now let's again connect back so you can see that now things I have you started with machine and let me go and sign in using my Docker ID.
But I can see that Docker is already running out here. I can if I wish I can go and switch to the next container as well. But let me just sign into my Docker ID in case if all else I can have some other issues as well quite some one sign in Just to keep myself safe, so that it is all things that set looks like I can just go to the settings and see yes, Docker is running I can open up the power shell. So I can open up my command out here. And I can just see that if I can find some Docker commands. So must be I can say.
So, if you look at some of the Docker commands, you know, which are which we will be using in our lecture. So, for example, Docker images, you know, this will tell you that if, if there are images, install images means for example, now you have an image of this project, right? You can have an image of the MVC five project and then from the images, we will create containers. So you can think about that images, images, I'd like templates saying that okay. This is the image for this MVC five project. This is the image for this project.
And then from that image, we create containers, right? So we can go and find some Docker commands just to check you know, for example, one of the Docker commands, which we can use to just check that if there are any Docker images so at this moment we don't have any Docker images. So our Docker is working at this woman which is great. And the next thing you know which is very important is in the C drive we need to go and copy our project so MVC five I don't know if this is copied properly or not because previously I had some issues so I'm going to go now back to ASP dotnet MVC five, I will copy Docker file, I will copy the Docker ignore file, and I will copy the bin file, right so both these three things I would go and copy and paste it out here.
Alright. So there it is. It is pasting. Let's Let's wait you know for finishing this, this copying over here. So, the first thing is once this thing is copied and pasted out here, we need to go and start running our Docker commands. So, the first command you know which you will be running out here or which you will be using to create the images, you will say Docker build.
So this will actually go and create a image Docker build hyphen t image name. So for example, now at this moment, this image is image MVC five and this.is. Very important. This just dot says run this command using the current directory. So what it will do is it will go to the current directory and it will search for that Docker file, Docker file of MVC five, and it will go and it will start executing these commands, and it will create an image right so that's the first thing. To create an image we have to say Docker build, hyphen, T the image name And remember that image does not mean that the instance is running to run the instance you know via to create a container so you can think about that image is like a template.
And from that image you can go and you can create multiple containers right? So to create a container the second command which is important is Docker run. So Docker build to create the image and Docker run so we'll say okay, Docker run so what is your image name my image name is let's say image MBC five and what is the name of the instance you want to create I'll say MVC five container right? So it will use this image MVC five and it will create a container called as MVC five. Now, when Docker runs definitely he will need you know the ports right at the end of the day web application runs on ports. So if you see the port, the way the port is, is is mentioned out here.
There are two numbers out here. So basically, there are two port numbers right. So, you can see I can just make this bigger. So, if you see out here remember our copying is happening happening at the back end. So, until that happens Let me explain this. So over here you have two port numbers one is the first number and one is the second number right?
So why do we need to port numbers remember that at the end of the day your container runs inside a metal inside a virtual machine inside a computer right. So and the ports are actually physical ports. So you cannot go and put the same port again and again for different application. So this first port here specifies in the port of the outer machine, and this this port out here specifies the port of your container. So for example, somebody can go and say HTTP localhost colon 80. And it will go and and map to your 80 port, but you can always go and make it 91 here.
So what this means is that if somebody will go and hit HTTP localhost at port, but internally, it will hit 91 inside your container, right. So at this point, what I'll do is I'll just keep it at 80, right? Because we are going to speak in 91. Right. So this means that you want to go and create an MVC five container, which will run the application at 91 port. But when someone will request, you know, to their virtual machine and at Port, it will automatically map or send that request to the 91 port, right.
So Docker built to create the image and Docker run. To create the instance from that image and the port numbers, you have to give both the host port as well as the container port so that you can see the copying has finished. So let's go first to the MVC five folder. So I'm going to go and just CD dot dot okay. Missy 501 happened isn't that MVC five oh CD MVC five change directory MVC five. Right?
So let's go ahead and find the first command. Remember that inside you whenever you file the command, the Docker file should be present. The dot doc ignore file should be present, right? So let's go ahead and say Docker build hyphen t image MVC five, do not forget this.or you will have a problem right? So I'm going to go out here, let me clear the screen so that you can see it properly. Let's see if everything works.
So I'm going to go and run this image MVC five. So there it is, you can see now it is actually going to the Microsoft ASP dotnet Look at that. It is downloading things from there. It will bring the whole ASP dotnet MVC five remember that as I've said previously, Docker does not go and clone an operating system. It actually An image of the necessity DLL solve the necessary binaries required only for that project for example at this moment you know you can see for MVC five so basically what it what is doing out here it is pulling from that from ASP Microsoft ASP dotnet. So very quickly what I mean as we can open this in Notepad a Docker file, so that I can show you parallely flow.
What happened to my virtual machine? open with? I'm paying seven rupees per hour. So Shouldn't the virtual machine be fast, isn't it? It's slow. Right?
It's waiting. Yeah. I'm trying to open that notepad file it is not. So basically you can see this from Microsoft ASP dotnet This is actually coming from From from her from this from Microsoft ESP dotnet. So that's the downloading taking place. After that, he will go to the bin directory and he will try to copy it.
So that's the next command after this. So, it will go inside the bin directory and he will try to copy it. So download complete that is good. So it's still downloading Okay, good. Finally it is opening. So, so, basically what I mean is, you know over here at this moment it is running this command from Microsoft SP dotnet and after some time we expect it to run this command copy been released right.
So, let us wait let us see what happens. And guys as as the extraction and the downloading is happening out here, you need to have patience out here. So please understand that you need to have patience, you can see that still my downloading is happening still my extraction is happening. So do not try to lose patience at some moment of time. will feel Like, the downloading has stopped or must be, you know, the extraction has stopped, you know, but give it some time, it will start, you know, doing things you can see it now, he has completed the first thing, it's actually completing the second thing. So let's wait so that you can see that he has completed all the steps so you can see step one of two.
So there were two steps right? So step one have to he downloaded Microsoft ASP net. Step two, he actually did the copy. And he has successfully built this image MVC five, right? So now I can go and I can do a list over here so we can go and we can just do a Docker list. Remember Docker images?
Let's see that. If the images that we can see here it's saying yes, image MVC five is there. You can also see that there is one more image here Microsoft ASP net because he has downloaded that, but our application is image MVC five right? So now that we have created the image now the next thing what we need to do is we need to go and create the container so I'm going to go and run this command out here and so we have so we have the image MVC five. So you can see we are going to go and use the image MVC five and we will create the container MVC five container right? So let us see if this runs or not, so you can see Docker run.
So remember guys, there are two important commands. One is Docker run. And the other one is Docker build. So, there you can see he has created the container. So now how do I test it? Let us go ahead open the browser and let us try to browse to localhost 8080.
So I'm going to go and try to just browse to Almost 80 come at almost just to localhost. When you go to localhost automatically it will use the 80 port right and I should see my MVC five application running. You can see it is not running. This is a problem with the with a CR actually, it cannot detect localhost right. So what we can do is we can go ahead and see that on which IP address is this MVC five containers running right. So how do we get the IP address by using the Docker info or Docker inspect I will say so I'll say your Docker inspect.
I want to inspect MVC five container So let's try to browse using the IP address. So that his IP address out here, right, so let's use this IP address. Copy. Remember that this is a problem with as you're actually, if you're doing it locally, I think the local hosts should work right? So they can use IP address. And I should see my MVC application running 172 3122 to 22 dot 218.
Yeah, there it is. You can see this MVC five running, right? So I'm just, you know, going through the commands. The commands we have used one is the Docker build. So if you remember we had the Docker build command, which helps us to build the image. Then we have Docker run which actually helps us to create the container and then finally we have Docker inspect you know to check you know what the Docker has and where it is running and a lot of other things as well you know you can see out here great now also we had our MVC core application running so as you can see right now, this is my host machine inside this I have the Windows operating system and in the Windows operating system, I have the Docker running and I have MVC file running in one container and the container name is MVC five container.
Now let us go ahead and try to do the same for MVC code right. So already I had have this MVC code here. So let us first copy all the files. So let us go ahead here and let's copy all the files what we have out here. So I'm going to go and open folders. Let me create The whole Docker demo, let me copy the whole Docker demo out here.
So I'm gonna go and try to paste it here inside this, right. So let's try to copy the whole Docker demo. Oh, you know what happens is you know in the terminal, normally, if you are opening in Visual Studio then it has some kind of an exclusive lock. So you can see like, I have just closed my Visual Studio. And let me try to repost it here. Let me delete it in case if some half files have been copied.
So I'm just copying the whole thing out there. Remember, for MVC core, you know, we are doing the build as well as the running everything on the production. For example, for MVC five, we were not actually doing any kind of build, right, the build what Bill had already happened in the bin release folder. So over here, now we're going to go and do both of them. Right. So it's copying out that let's let's give it some time.
So this is what I have done now I have copied the folder, right. But I also have done some changes out here. So what I did is I created a separate folder called as Docker demo inside that you know we have this ASP dotnet code and I deleted MVC five remember we had MVC five, you know that I deleted everything. And so those all I deleted and the Docker file and the Docker ignore file, I put it onto the Docker demo. So remember the main folder is Docker demo. Inside this unit we have the solution file.
We have the Docker ignore file, and we have the Docker file. Also one very important point which I made a mistake in the previous MVC five in MVC five I named this file as doc ignore that is wrong. It should be doctoring. So I'm so sorry for this this name is dot Docker ignore and not dot dot doc ignores right? For me sci fi it worked but for MVC core it don't work so I would suggest that keep the dot Docker ignore file. So in this you know I've just said that exclude the bin folder and the OBJ folder right so, and also in the solution file in the solution file I removed the project of MVC five you can see I just kept the MVC core project.
So if you look at the solution file for now, so we have this solution file out here. So, if you go and if you if you go and if you just see the solution file, the solution file at this moment had two projects right. So it must be I can just go to the folder and we can just have a look at the solution file in Notepad. So if you see the solution file in Notepad, you can see that there are That should be two projects I'm not sure why it does not show two projects. So over here let me go if you see this solution file it has two projects yeah there it is. I think I removed it I so one is the ASP dotnet core and ASP NET MVC five.
But what I did is I just removed that other project because now we are talking only about MVC core right? So what I did is you know, I went ahead and I removed you know, the MVC five projects so that while I do my MVC core deployment, I don't want the MVC five to interfere right because they're already been deployed. So I've done a couple of changes I corrected my doc dot Docker ignore file. I kept one root directory, you know, where I put my Docker Docker file, my solution file, and the ch proj file is inside this So remember, the Docker demo is the top folder. Inside that, you know, we have our SLN file, we have our Docker file we have our Docker ignore. And then we have the ASP dotnet code which has the ch proj file, right.
So now, according to this, you know, this is how the Docker file is now looking like. So first thing, go ahead and get the SDK. So that is step one. Second, make your working directory as Docker demo. So you basically come to the root directory. Then we copy both the solution file and Cs proj file into the current project into the current current folder.
And we do dotnet restore with this, what will happen is all the nuggets will get installed. And after that, we copy the remaining DLL files and other views and we run dotnet publish, okay, and then remember that this was all for the building purpose. So if you want to build that We have this build. Now then the second thing is we have the runtime for running, you need to run need to have the runtime. So I'm going to the runtime, and I'm copying into whatever has been built into the output folder. When you actually do a dotnet publish, it builds to the output folder, you can see here, I've named the folders out.
So from this out folder, he copies to the build, and then say, Okay, now go and the entry point is ASP, dotnet core DLL. So that's how this whole syntaxes so now let's go go here again. So if you see at this moment, we only have the MVC five image. So I'm going to go now and say, Docker build, image MVC code. So you can see I'm running the Docker build in the main folder, right? So I'm going to go and run this image MVC code.
So there it is, press enter. So it will now go ahead, it will bring all the SDK from online We'll then go ahead and run the other things you can see here, there are total 11 steps. Forget about the comments The comments are the hash. So 1-234-567-8910 and 11. So we can see now it is doing one of 11 and then it will do two of 11. So whenever you get an error, it will actually tell you, it will actually tell you know, on which line number is the problem.
So, by looking at the step numbers, you can have a fair idea of which line number is a problem. So, let's give it some time and let the download finish. And it's now doing one of 11. So, let us wait for some time. So there it is, it is extracting the last bits now you can see two of 11 two of 11 is nothing but the working directory then three of 11 copying the solution file. Then we have five of 11 123 For five, running the dotnet restore command right.
So, swing a dotnet restore. And then after that, it will go and it will download the runtime. So, you can see here it is doing a dotnet restore dotnet restore will take some time because it is nothing but then I get command. And after that six of So once this started, his story's done, he will then do a copy. And then we can see he's copying that copying we finish. And now you can see he's doing a dotnet publish.
So this is the commander of dotnet publish out here and you can see things are moving ahead. Once this is done, your image will be created right. So the store completed that is good. Remember that when he does a dotnet publish the first thing he does first in dotnet does is it actually does a restore it gets all the files. And there it is just now Restoring completely. And you can see now he's now starting the step eight.
Step eight means downloading the runtime, because without the runtime, you cannot install it and 911 and then afterwards it will copy to the output folder. And finally the entry point. So that is 11 of 11. Very great. So there it is, right? So if you now go and say Docker images, so we can see that image MVC code is out here right?
Now in order to go and create an instance or to create an container, remember our command, we need to say, Sorry, we need to say dotnet run right? So I'm going to go and copy this dotnet run out here and we will say dotnet run. So remember that already on 8080 port things are running. So what we can do is we can say Okay, how about at one port that will go to the nine Port must be 91 port or 92 port. And we will create an MVC core container, right? So let's give a name as MVC core container.
And we will use the image MVC core, right? So that's image MVC core. And let's run it. So that you can see now it is creating a container it has already created, and we can just do a Docker inspect that container so that we can get the IP address right MVC core container, and let's see the IP address. So there it is. So this is where your MVC core application is now running.
So if I go and see here, HTTP localhost. So this will run MVC code. And remember, we also had Docker inspect MVC five containers. So in the MVC five container we had, this was different IP address. So this was MVC five. So 172 31 218 HTTP.
Alright, so this is MVC five, right? MVC five MVC course. So that's what the what, that's what the beauty of containers are. You can see now, he has not cloned the whole OS. So that is a Docker in between. So first thing, we have the infrastructure layer.
Then we have the operating system. On the operating system, we have the Docker, and Docker has created two containers. One is this ASP dotnet core container, which has the dotnet core SDK, the dotnet core DLL. And then we have the MVC five, which has dotnet framework 4.7, or whatever it was, and the MVC thing, right? And then why not, you know, we can have one more container which is Java container, and it has Apache, and it has SQL Server, Oracle right in it. So the point about containers is that it helps you to go and deploy my Services very easily.
So if you think about the virtualization way of doing deployment, that would have been really tough, right. So summarizing, first thing, you need to go and create your project architecture in such a way that you have to decouple systems which have their own database, which have their own source code, which have their own things, and the only way they will communicate to each other. So when any project wants to communicate to the other project, in a microservices project, they will use HTTP calls. After that, for every project, you will have two files one is a Docker file, and one is a Docker ignore file. And then you will go and you will run the dotnet build command first. So so the build command will help you to go and create an image while the Run command right will actually help you to go and create a container.
And then you can go and happily run both the containers inside the same machine. Now at this moment, I have used windows Dockers, but you can always go and you can see switch to the Linux container so you can have a Linux container. And inside that you can do things right. Now guys, I would like to also run you through some important syntaxes of Docker. One is that you can see Docker build that helps you to create an image Docker run that actually helps you to create an container. Docker images actually help you to see the current images in your in your operating system.
Docker container tells that you know how many containers are there. Remember, images and containers are different images or templates. Containers are instances of it right? Docker inspect you know helps you to inspect and container so for example, I can set up Docker inspect MVC core five, right remember, and that will help you to tell you you know what that thing has. Docker stop helps you to stop an image. You can see two syntaxes out here I have said docker ps and Docker images, if you want to go and delete all the images and if you want to go and delete all the things you know from from your computer, you can use both of these syntaxes for example, I can first go and delete all the containers by using this.
For that, you know, we need to use PowerShell. So PowerShell you can go here to any Windows operating system, and you can have PowerShell. So if I go and paste this out here, this will actually go and try to remove that. You know, that image you can see now the first thing what he's saying is that, oh, we cannot remove it, because at this moment, both of the instances are running right. So let us do a Docker. Let's see.
Docker containers. So if you want to go and see the containers, remember the syntax, Docker container list hyphen, a. So let's go ahead and see Docker container, list hyphen, a. So these are the containers so I can just say Docker stop image, MVC code, we can stop that Sorry, these are the the container This is the image name image MVC core. The container is MVC core container I am so sorry. So I just said Docker stop the container name.
So MVC core MVC core container, right? And then I can see too that stops that. And then we can say Docker stop MVC five containers. Because if you don't stop the container, it does not allow me to delete it. Remember that you can go and you can always write the big script, you know, or big PowerShell command and put all the syntaxes into one file right? At this moment, you know, from teaching perspective, I'm just making a difference.
So now I can go and run this. So this actually does a for each kind of a loop. So you can see this is Docker, remove that container what we have, so now this will, this will remove the container. Now that that removes the container. If you want to go and remove the images, then this is what we have Right. So this will go and remove all the images so I'll say Docker this that should go and remove all the containers right so in case you want to go and delete all the images in case you want to go and delete all the containers that's what it is in case your containers has problems sometimes you know what happens is you create a container but it just does not start must be the port is blocked or must be there are some issues so you can say Docker log and the container name and once you do that, he will show you a log file you know of everything from where you can understand you know, what kind of issues you have, right?
So guys this Docker help file dot txt, you know, I am giving it to you as a download. In this help file, I have put the following things first thing is below is the doc one is the syntaxes. So let me just write down here. One is, these are some important commands, right in this. The second one is this is a Docker file. For MVC core so this from here to here is the Docker file from MVC Cove, right?
Remember that when you create a Docker file the name should be Docker file without an extension, right? And for MVC five so this is a third thing in this text file for MVC five. This is for MVC five, right? And step three Don't forget, you also need a Docker ignore file. So that's what it is right? So I put some code snippets out here which are important, but always remember first thing you need to create a dockerfile without any extension that is the first point to remember.
The second point is Docker ignore file. This needs a dot ahead right ignore so please ensure that you have a.or Docker ignore file and that you put the files for the need to be ignored. And one important thing when you said Dr. Bill, don't forget this dot each points towards the current directory So for Docker build, please put the.at the last so that it shows the current directory. So this Docker help file is there as a download in this video, which can be will help you to go through the syntaxes which will help you help you to get to the sample code. So I hope that you enjoyed this video. Thank you