Deploying Node - Js App To AWS EC2 With Docker
Deploying Node - Js App To AWS EC2 With Docker
Steps:
2. Clone the repository from GitHub to your ubuntu server using command:
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.
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.
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”]
To build an image using Dockerfile, Go to the directory that has your Dockerfile and run
the following command
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!