Project using a Docker File
Pull the repository using the Url mentioned below
https://github.com/LondheShubham153/node-todo-cicd.git
At first, we will figure out what type of files the repository contains.
We can see files with extension .js here, which means we will be have to create a container that can run a javascript file .
Now create a file with the name Dockerfile, and open it using a text editor.
FROM node
: It is creating a base image of nodeWORKDIR app
: It is setting the working directory as app.COPY . /app
: It means that copy everything from this directory to the container working directory (/app)RUN npm
: Run command is executed during the image formation step.So here we are installing npm , which is a Node Package Manager.RUN npm run test
: This runs a predefined command specified in the"test"
property of a package's"scripts"
object.CMD ["node","app.js"]
: Whendocker run
will be executed it will execute this command and app.js will start running inside our container.EXPOSE 8000
: here we are exposing port 8000 of the container
Once you have written the Dockerfile, run
docker build . -t <image_name>
, it will create an image from our Dockerfile.Run
docker run -p 8000:8000 <image_name>
, the run command will create a container, -p 8000:8000 means we are mapping our system port number 8000 with the container port 8000.Now go inside your Google Chrome tab with local_host IP:8000
- Note if the web page is not loading go to the inbound group of your ec2 instance and add port 8000.
Thank you for reading!!