0% found this document useful (0 votes)
70 views

Deploying Node - Js App To AWS EC2 With Docker

The document provides steps to deploy a Node.js web app to an AWS EC2 instance using Docker: 1. Launch an AWS EC2 ubuntu instance and clone a GitHub repo containing the app code. 2. Create a Dockerfile that defines building an image using the node:alpine base image, copies the app code and installs dependencies. 3. Build the image using the Dockerfile, run it as a container exposing port 8000, and open it in a browser using the EC2 public IP address.

Uploaded by

Rathod Chintu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Deploying Node - Js App To AWS EC2 With Docker

The document provides steps to deploy a Node.js web app to an AWS EC2 instance using Docker: 1. Launch an AWS EC2 ubuntu instance and clone a GitHub repo containing the app code. 2. Create a Dockerfile that defines building an image using the node:alpine base image, copies the app code and installs dependencies. 3. Build the image using the Dockerfile, run it as a container exposing port 8000, and open it in a browser using the EC2 public IP address.

Uploaded by

Rathod Chintu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Deploying Node.

js web app to AWS EC2 with


Docker

Steps:

1. Launch AWS ubuntu ec2 instance.

2. Clone the repository from GitHub to your ubuntu server using command:

git clone <repository_URL>

3. Create a Dockerfile

The first thing we need to do is define from which image we want to build from. Here we
will use the node:alpine image available from the Docker Hub.
FROM node:alpine

Next we create a directory to hold the application code inside the image, this will be the
working directory for your application:

WORKDIR /app

Then copy package.json file to the working directory using COPY instruction.

COPY package.json /app

This image comes with Node.js and NPM already installed so the next thing we need to
do is to install your app dependencies using the npm binary.

RUN npm install

Copy your app's source code inside the Docker image, use the COPY instruction:

COPY . /app

define the command to run your app using CMD which defines your runtime.

CMD [“npm”,”start”]

4. Build an Image using Dockerfile

To build an image using Dockerfile, Go to the directory that has your Dockerfile and run
the following command

docker build -t <image-name> .

Example: docker build -t node-app:v1 .

By using docker images command we can see the list of images


docker images

5. Run the image to create a container


Running your image with -d runs the container in detached mode, leaving the container
running in the background. The -p flag redirects a public port to a private port inside the
container and –name flag is for container name.
Run the image you previously built:

docker run -d - -name <container-name> -p 8000:8000 <image-name>

docker ps command is used to list all the containers.

6. Go to your ec2 instance security groups and check whether port 8000 is
opened or not. If not, then edit the security group and add the port no. 8000 to the
security group.

7. Open the public IPv4 address of your ec2 instance with port no. 8000

http://Public-ip:8000
Thank you for reading! Hope it helps!

You might also like