Creating  a "To do" Application Docker file

Creating a "To do" Application Docker file

git link: https://github.com/narkhedeakshay26/node-todo-cicd.git

Create a docker file for Node.js

Use the git clone command to clone the repository

$git clone https://github.com/narkhedeakshay26/node-todo-cicd.git

Then we will start creating a Docker file in the "node-todo-cicd. git" directory. So make sure you change your directory before proceeding.

Search "node js docker file" on google

Just like Github, docker has its own Docker hub.
Link for reference: https://docs.docker.com/language/nodejs/build-images/

We will follow the standard procedure:
1. Declare From
2. Copy source to destination
3. RUN.. the requirements
4. EXPOSE #### (Assign the port)
5. cmd

Creating a docker text file

#Note: Never create DockerFile.txt

$ vim DockerFile

#Never create DockerFile. I renamed the DockerFile to "Dockerfile"

Error you will face if you use DockerFile:

ubuntu@ip-172-31-81-73:~/node-todo-cicd$ docker build . -t node_todo_app:latest
#Error:unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/ubuntu/node-todo-cicd/Dockerfile: no such file or directory
ubuntu@ip-172-31-81-73:~/node-todo-cicd$ ls
DockerFile  Jenkinsfile  README.md  app.js  docker-compose.yaml  package-lock.json  package.json  test.js  views

To rename the file:

# mv Current_name New_name
$ mv DockerFile Dockerfile

To build the docker file run the following command:

$ docker build . -t node_todo_app:latest

To see all the docker images on your system:

$ docker images

To run this "node_todo_app", we will need to assign the port on the EC2 instance.

Steps: EC2 instance > Security Tab> Security Group

To set an inbound rule:

Edit inbound rules >> Add rule >> Custom TCP >> Port 8000 >> Anywhere IPv4

Click on Save rules.

Now we gain access for all IPv4 8000 port access.

Now we will run the docker file on port 8000

$ docker run -p 8000:8000 -d node_todo_app:latest

Remember like this " Docker run the port "-p" on 8000:8000 in the background "-d" the "docker image".

Check the docker file running

$docker ps

Now copy the Public IPv4 address of the instance created:

Open browser >> Enter Public IPv4 address and add assigned port at the end: