<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammad Abdullah Khan</title>
    <description>The latest articles on DEV Community by Muhammad Abdullah Khan (@abdullah0332).</description>
    <link>https://dev.to/abdullah0332</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F486078%2F3bf20081-c35b-4579-8e41-035744aee4fd.jpeg</url>
      <title>DEV Community: Muhammad Abdullah Khan</title>
      <link>https://dev.to/abdullah0332</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdullah0332"/>
    <language>en</language>
    <item>
      <title>Dockerize a Node app and deploy to Heroku</title>
      <dc:creator>Muhammad Abdullah Khan</dc:creator>
      <pubDate>Sat, 03 Sep 2022 20:06:46 +0000</pubDate>
      <link>https://dev.to/abdullah0332/dockerize-a-node-app-and-deploy-to-heroku-4nf4</link>
      <guid>https://dev.to/abdullah0332/dockerize-a-node-app-and-deploy-to-heroku-4nf4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node&lt;/li&gt;
&lt;li&gt;npm&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Create a node.js app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, let’s create a simple node.js(express) application, to get started with express.&lt;/p&gt;

&lt;p&gt;Create project by running npm init -y and copy paste the following lines in package.json file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  “name”: “heroku_docker”,
  “version”: “1.0.0”,
  “description”: “Deploy Dockerized NodeJS Image app on Heroku”,
  “main”: “index.js”,
  “scripts”: {
     “start”: “node index.js”,
     “dev”: “nodemon index.js”
  },
  “author”: “”,
  “license”: “ISC”,
  “dependencies”: {
    "dotenv": "^16.0.0",
    "express": "^4.18.1",
    "nodemon": "^2.0.16"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a file named index.js which is our express app, and add the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require("express");
require("dotenv").config();
const PORT = process.env.PORT || 3000;
const app = express();
app.use("/", (req, res, next) =&amp;gt; {
  res.send("Node JS backend is running");
});
app.listen(PORT, () =&amp;gt; {
  console.log(`Server is listing on PORT : ${PORT}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create .env file and add PORT&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PORT=3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s try to run our app in the terminal,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install
$ npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t6nJPN_N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zxuvq6hovn2maa72yd6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t6nJPN_N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zxuvq6hovn2maa72yd6x.png" alt="Image description" width="314" height="91"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open Browser and type localhost:3000&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nLzmJsNL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fo7jt1g4d4dxxsdq1zz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nLzmJsNL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fo7jt1g4d4dxxsdq1zz.png" alt="Image description" width="336" height="89"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Set up the Dockerfile&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The next step is to create a Dockerfile.&lt;/p&gt;

&lt;p&gt;If you haven’t installed docker in your system, visit &lt;a href="https://docs.docker.com/get-docker/"&gt;here&lt;/a&gt; to download it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dockerfile:&lt;/strong&gt; you can think of the Dockerfile as a receipt — it includes instructions on how to create a Docker image&lt;br&gt;
&lt;strong&gt;Docker image:&lt;/strong&gt; the output of the Dockerfile run — this is the runnable unit&lt;br&gt;
Add the following in &lt;strong&gt;Dockerfile&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM node:alpine
# CREATE APP DIRECTORY
RUN mkdir -p /app
WORKDIR /app
# INSTALL DEPENDENCIES
COPY package*.json ./
RUN npm install
COPY . .
# Exports
EXPOSE 3000
CMD ["npm","start"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;FROM node:alpine&lt;/code&gt; — &lt;em&gt;From the base image &lt;strong&gt;node&lt;/strong&gt;, with &lt;strong&gt;alpine&lt;/strong&gt; variant.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WORKDIR&lt;/code&gt; — &lt;em&gt;We are mentioning that the directory called &lt;code&gt;app&lt;/code&gt; is going to hold our project. If the directory specified doesn’t exist in the image, it is newly created.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;COPY package*.json ./&lt;/code&gt;— &lt;em&gt;We are copy our package.json and package-lock.json to our workdir.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RUN npm install&lt;/code&gt; — &lt;em&gt;This command installs the dependencies mentioned in our package.json.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CMD [ "npm", "start"]&lt;/code&gt; — &lt;em&gt;Executes &lt;code&gt;npm start&lt;/code&gt; , which is the command to run our app.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Login to Heroku and create app&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the following commands to login in heroku and create app on heroku. Copy the name of Heroku App.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ heroku login
$ heroku container:login
$ heroku create
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eHepO1kD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7b2ofmpg8h66dkqobaxo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eHepO1kD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7b2ofmpg8h66dkqobaxo.png" alt="Image description" width="880" height="172"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Build the image using Dockerfile&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Being in your project directory, run the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker build -t registry.heroku.com/&amp;lt;HEROKU_APP_NAME&amp;gt;/web .
e.g docker build -t registry.heroku.com/heroku-docker01/web .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vfEi_4eK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/milk2ys8nzto79br15gr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vfEi_4eK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/milk2ys8nzto79br15gr.png" alt="Image description" width="880" height="424"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker push registry.heroku.com/&amp;lt;HEROKU_APP_NAME&amp;gt;/web
e.g docker push registry.heroku.com/heroku-docker01/web
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vzkavp9c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aznehfd8arrs7g10s6ty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vzkavp9c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aznehfd8arrs7g10s6ty.png" alt="Image description" width="880" height="201"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ heroku container:release web -a &amp;lt;HEROKU_APP_NAME&amp;gt;
e.g heroku container:release web -a heroku-docker01
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MyN8q3Uq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cj4mzgiqkcjcc2q5fki.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MyN8q3Uq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0cj4mzgiqkcjcc2q5fki.png" alt="Image description" width="878" height="58"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After Image release on heroku app click on open app in heroku.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jjBy8qdO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ad0twecpyhoepr2sico.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jjBy8qdO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ad0twecpyhoepr2sico.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Github repo — &lt;a href="https://github.com/Abdullah0332/heroku-docker"&gt;https://github.com/Abdullah0332/heroku-docker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Learning!!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>AWS Private vs Public vs Elastic IP</title>
      <dc:creator>Muhammad Abdullah Khan</dc:creator>
      <pubDate>Sat, 03 Sep 2022 19:55:56 +0000</pubDate>
      <link>https://dev.to/abdullah0332/aws-private-vs-public-vs-elastic-ip-idl</link>
      <guid>https://dev.to/abdullah0332/aws-private-vs-public-vs-elastic-ip-idl</guid>
      <description>&lt;p&gt;Networking has two sorts if IPs:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;IPv4&lt;/strong&gt;: 192.168.1.1&lt;br&gt;
&lt;strong&gt;IPv6&lt;/strong&gt;: 1900:4545:1:101:f8fa:f2op:12ef&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let talk about Public IP, there are different type of IP like,&lt;/p&gt;

&lt;p&gt;If we have a web server that is public IP &lt;em&gt;79.216.59.75&lt;/em&gt; and we have another server with have another IP &lt;em&gt;211.139.37.43&lt;/em&gt;, these server is accessible on www using this IP and using these public IPs these server can talk with each other.&lt;/p&gt;

&lt;p&gt;Lets consider we have an company A who have an private network like &lt;em&gt;192.168.0.1/22&lt;/em&gt;. Private network have some private IP ranges and all the computers inside that private network can talk to each other using the private IP. But these IPs are not accessible on WWW, to make it accessible on WWW we use &lt;a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html"&gt;Internet Gateway&lt;/a&gt; (public). Internet Gateway enable private network to talk to other server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AeRhE2yy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1o8uwnkacy5v1jgf3xi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AeRhE2yy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1o8uwnkacy5v1jgf3xi.png" alt="Image description" width="880" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private / Public / Elastic IP Difference :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Private IP (IPv4):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Public IP means the machine can be identified on internet (WWW).&lt;/li&gt;
&lt;li&gt;Must be unique across the whole web (not two machine can have the same public IP).&lt;/li&gt;
&lt;li&gt;Can be geo-location easily.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Public IP (IPv4):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Private IP means the machine can be only be identified on a private network only.&lt;/li&gt;
&lt;li&gt;The IP must be unique across the private network.&lt;/li&gt;
&lt;li&gt;But two different private networks (two companies) can have the same IPs.&lt;/li&gt;
&lt;li&gt;Machines connect to WWW using an internet gateway (a proxy).&lt;/li&gt;
&lt;li&gt;Only a specified range of IPs can be used as a private IP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Elastic IP:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With the Elastic IP address, you can mask the failure of an instance or software by rapidly remapping the address to another instance in your account.&lt;/li&gt;
&lt;li&gt;You can only have 5 elastic ip in you account (you can ask AWS to increase that).&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Overall, try to avoid using elastic IP:&lt;br&gt;
1) They often reflect poor architectural decision.&lt;/p&gt;

&lt;p&gt;2) Instead use a random public IP and register a DNS name to it.&lt;/p&gt;

&lt;p&gt;3) Or as we’ll see later, use a Load Balancer and don’t use a public IP.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Private and Public IP (IPv4) In AWS EC2 — Hands On&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By default, you EC2 machine comes with&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A private IP for the internal AWS Network.&lt;/li&gt;
&lt;li&gt;A public IP for the WWW
When we are doing SSH into our EC2 machines:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can’t use a private IP, because we are not in the same network.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We can only use the public IP.&lt;/li&gt;
&lt;li&gt;If your machine is stopped and then started the public IP can change&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
