 Hello guys. So in this video, we are going to see how to host a Node API endpoint on Docker and push that Docker container to Docker repository. So let's get started. So first of all, we have four prerequisites for the same. The first one is you should have Node install union machine. There is a link from where you can download and install it. Second, we should have Docker installed on the machine. There is a link from where you can install Docker. Third is you should have Docker Hub account credentials. If you don't have any Docker Hub account, you can create it from Docker Hub. And the last one is you should have any code editor. Next, we have to follow some steps. So I'm just elaborating it so that we can follow that steps. The first one is we need to create a node project, which we want to host on Docker container. Next, we need to create a Docker file with some instructions. Next, we need to log into Docker Hub from the console so that we can push the project and we can push the image. Next, we need to create a Docker image from that instruction file we have created. Then we need to run the Docker image inside the container. And finally, we will be pushing our Docker container image to the Docker Hub repository. So let's get started. So here we are inside this Node Docker app folder, which is empty for the time being. So let's create a new project in Node by writing npm in it. And I will be skipping all the prompts by using this Y flag. Okay, so once your project is created, what you can do, you can quickly create a new file, index.js. And what we need, we need a dependency of Express as well. So let's install the same npm install xpress. So let's clear this and quickly write our code over here const app is equal to require express. And we use function over here. And now we need to do app dot get. And we just create one route. And we need to use this request response arrow function semicolon. And here we need to use we need to send the response.json. You can send any kind of data. So I'm just taking one json object. And I just give it key. Let's say message and the value I will take. And just change this on the stick. So done with this. So once the endpoint is ready, we need a port as well. Let's create a port is equal to process dot environment dot port. If it is not there, we can specify our own port. Let's keep it 8080. And finally, we need to do app dot listen. So here we need port number. Let's give it port and one callback, which is console dot log and simply saying. So here I will be using back tick so that I can do interpolation. So app is listening on HTTP colon local host colon. We need to use port here. Let's use port and that's all for the coding part. Now next, we need to create a new file. Let's name it Docker. Well, and here we need to write some instructions. So it always start from from and here we need to specify the image name. So as we are working with the node, so let's quickly search for node image. And yeah, go for the submachine image. And let me check for the version I have or you can check for the latest version for the node. Let's say node download or you can say latest version that is 18.3.0. So I just copy this and check for this image. You can choose any image. That's not issue. Yeah, we have this so I can do what I just use that image over here. So here we need to use node colon this tag. Next, we need to use work directory that would be our app folder. So let's use like this. And now we need to copy the content from this directory to this app. So this dot means current directory everything. So we don't want to. Okay, let me go ahead with this. So once the code is copied, we need to run run NPM. Install, which you're going to install all the dependencies. So we don't need to push this into that image. So for that, what I can do, I can just create a dot docker ignore file. And I can mention that node underscore modules is not required. Yep, just save it. Come back. And once it is installed, we need to expose it on some port. Let's use any port. Let's use 8080. And finally, we need to use command. So I have already installed this docker extension. That's why it is giving me suggestions. So if you want, you can install the same. So this is recommending this way. There are different ways to do so. The one way is this one. Let me just use this way. That is node. And the second argument would be index.js. This is one way. If you don't want to use this, you can also use like this CMD node in text.js. You can choose any of these. So you can go ahead with any of these. Let's save it or I just come into this and let's use this one. This is the recommended way by docker hub. So let's use this one, although both will work. So this instruction file is complete. Now what we need, we need to do login with a docker. So first of all, I have node hyphen v version node is already there. Okay. And I have docker hyphen version docker is already there. So docker looks like this docker desktop on windows. So currently I don't have any image or container. That's why it is coming empty. So I have already logged in with the console. Let's log in. So I have already logged in. That's why it is saying authenticating with existing credentials. Login succeed. In your case, it would be asking for username. That would be this username that you have used on this docker hub. And the password. Okay. So let's go here. Once it is locked in now, I need to run a couple of commands. Let's clear this. First of all, I need to create a image build command is there. So docker build hyphen t that is tag name and then the naming convention. So I'm following the standard naming convention that is your username. That's the gender. Burma forward slash then your project image name. So I say go for node demo and then colon like this version 0.0.1. And finally dot R E L E A S B release. This is the standard way your username, your image name, colon, then version. And if it is released, then you have to specify dot release. Although you can specify any, any name, but this is a standard convention. And lastly, you need to specify dot so that you can push all the content into this docker image from this folder. Let's press enter. So it will take some time. So I'm going to fast forward this video. Okay. So it has taken some time and you can see all these commands are used. So it has taken near about one 73.5 seconds. So what we need to remember, we need to remember this because we have to use this image. So I just copy this. Okay. And what next we need to do, just go to this desktop of Docker and you can find your image is now available under this image section. So what next we need to do image is done. Now next we need to run one more command that is Docker container Alice, which will show the list of containers. So currently we have not created any container. So that's why it is not coming. So let's write the command to create the container here. Docker container run hyphen D this is for the test mode. If I will not use it, so it will stick to this terminal. So I will not be able to use this terminal. So it will be logging on this terminal. So I don't want to attach it. So that's why I'm using the touch mode. Next is hyphen P for port. So we want to run it on 3000 port. That is my local port on my machine and which port you want to bind. So we need to bind this port with 3000. So on my local machine, it would be running on 3000 port. So let's simply specify 8080 and here we need to specify that name. So let's paste it. So it will take some time. So you can see now it is in running position. So that means it should be working on this localhost 3000. So let's copy this, go to the browser and check whether it is working or not. Okay, so it is working successfully. Now we left with the last step that is pushing our image to this Docker hub repository. Before that, you can simply write Docker container ls and you can see your Docker over here. Here your container is working and if you want to stop it, simply say Docker stop and this name you can specify. You can use simply you see one and it will identify this and stop it. ls command again and see Docker container is working or not. Okay, so now finally, we need to just use Docker push and the image. So image we can copy it from here. Otherwise, you may commit some spelling mistake, paste it and so once you push it, it would be coming over here. So it is pushing, let's wait. So now you can go back here and you can refresh it and you can see this node demo is here. Now anybody can use this image simply by using this Docker pull and this full command. So that's all for this video. Thank you.