Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Build, Deploy and Run Node Js Application on Azure using Docker

39 views

Published on

Build, Deploy and Run Node Js Application on Azure using Docker,

This documentation explains step by step how to Build, Deploy and Run Node.js application on Azure using docker.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Build, Deploy and Run Node Js Application on Azure using Docker

  1. 1. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 1 This documentation explains step by step how to Build, Deploy and Run Node.js application on Azure using docker. The following Source code will be used as test and can be checked from here. Requirements:- • Azure Account (Sign up for a free $200 credit) • Git (Install on the computer) • Docker (Install on the computer) • Node.js (you can use the above link to clone the code). Let’s work !!! Step #1:- After logging to the Azure account, as initial step we must create something called container registry ( ACR will be used later as refer to Azure container Registry) which allows you to store your custom container images privately in the Azure cloud. Access to azure portal from the following link :- https://portal.azure.com/ Figure 1 Create container Registry Then After access the container registry page, press add
  2. 2. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 2 Figure 2 add ACR Screen And fill the information depends on the requirement you have. Figure 3 Create ACR And Press create. Wait for couple of second/minute till it will be created, azure will notify you (Notification section) once it’s completed. Step #2:- Once the ACR will be created, press on it, and it will take you to the information about the created ACR, the following information will be needed later.
  3. 3. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 3 Figure 4 ACR Login information Step #3:- We need to check the docker login, open Power shell/terminal depends on operating system you are using, to authenticate to ACR and validate the credentials. Figure 5 Test docker Login using ACR information
  4. 4. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 4 Figure 6 Test Result, Login Succeeded You should see a message that says, “login succeeded”. As Figure 6. Step #4:- We need to clone the sample code from https://bitbucket.org/network-international/node-js-getting-started/src/master/ Git command should be installed, to do this just press on this link here. Fire the below command on the PowerShell/terminal/command promote. git clone https://github.com/heroku/node-js-getting-started.git Figure 7 Using Git to clone the code After you've cloned the repo, switch into the application directory: You will find files, create file call it Dockerfile (without any extension).
  5. 5. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 5 Figure 8 Dockerfile inside cloned repo Inside the file write the following :- Descriptions : - • FROM node:alpine, The FROM command defines the base container image, and the operating system will be Alpine Linux. • WORKDIR /usr/app define the working directory and is where we'll store the application code and if it’s not exists on the OS will be created during the process. • COPY package*.json ./ used during the build process to add the package.json and package-lock.json files to the working directory. • RUN npm install used to execute npm install which will ensure our application dependencies are included within the container image. • COPY . . this is to copy the application source files into the working directory. • CMD ["npm", "start"] defines the default command to execute when the container starts. Step #5:- To do this step, you should be in the same directory as the Dockerfile. Use the docker build command to create your container image, the below command will tell Docker to build your image using the Dockerfile in the current directory. FROM node:alpine WORKDIR /usr/app COPY package*.json ./ RUN npm install COPY . . CMD ["npm", "start"] docker build -t demonetwork.azurecr.io/node-docker-demo:latest .
  6. 6. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 6 Figure 9 Build docker image using dockerfile Step #6:- Now we test the login to our docker before, let’s push our image to ACR using the below command, Figure 10 Push the docker Image to ACR docker push demonetwork.azurecr.io/node-docker-demo:latest
  7. 7. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 7 Figure 11 Pushing the docker image completed After the command completes successfully, you can head back to the Azure portal to verify that your image is now available in ACR. Figure 12 Verify the command Step #7:- The final step, which is expose the docker application using URL, Azure make this step easy, by creating resource called Web App for containers, to do this just follow the below figures. In the Azure portal, select Create a resource, select Web in the Azure Marketplace, and choose Web App for containers.
  8. 8. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 8 Figure 13 Create web app for containers Press on web app for containers Figure 14 Create Web App for containers New page will be open, fill the information, such as the name of instance, will be publish either on Linux or docker container ( our case) , don’t press review + create, press Next: Docker, so you will be able to configure the web app.
  9. 9. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 9 Figure 15 Web App Instance details The next screen, which is docker, as you see, I choose “ azure container Registry” and from the drop list, will be appeared our options. Figure 16 web app container configuration Press review creates.
  10. 10. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 10 Figure 17 Web App Summary Page Wait for couple of seconds and it will be created. Figure 18 Final Result with URL for the new deployed code As you see if you check the URL and press on it This is the result. https://networktask.azurewebsites.net
  11. 11. Build, Deploy and Run Node Js Application on Azure using Docker Osama Mustafa P a g e | 11

×