Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Docker 5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Experiment -2.

1
Student Name: Tarush chauhan UID: 22BDO10073
Branch: AIT-CSE-DevOps Section/Group: 22BCD-1(B)
Semester: 5 Date of Performance: 16-09-24
Subject Name: Docker and Kubernetes Subject Code: 22CSH-343

1. Aim/Overview of the practical:

To run a node.js application using Docker and manage the Docker volume.

2. Apparatus: PC, Docker Engine, DockerHub, Ubuntu Linux

3. Steps for experiment/practical:

● Dockerfile:
1. A Dockerfile is a script that contains instructions for building a customized docker
image.
2. Each instruction in a Dockerfile creates a new layer in the image, and the final
image is composed of all the layers stacked on top of each other.
3. Dockerfile uses a simple, easy-to-read syntax that can be created and edited with
any text editor.
4. Once a Dockerfile has been created, it can be used to build an image using the
docker build command.
5. Dockerfiles enable faster and more efficient deployment of applications.
6. Dockerfiles can be used in automation testing to build and run test environments
for different applications and services.
7. We can easily integrate your Dockerfile with continuous integration and
continuous deployment (CI/CD) pipelines.

● Some Dockerfile instructions:


1. FROM: specify the base image we want to start from.
2. RUN: used to run commands during the image build process.
3. COPY: used to copy a file or folder from the host system into the docker image.
4. EXPOSE: specify the port you want the docker image to listen to at runtime.
5. WORKDIR: used to set the current working directory.
6. VOLUME: used to create or mount the volume to the Docker container
7. CMD: Executes a command within a running container. Only one CMD
instruction is allowed, and if multiple are present, only the last one takes effect.

● Node project and docker image creation


8. Create a folder for the project and create a file named “hello.js” in that folder.

var http = require('http');

http.createServer(function (req, res)


{ res.writeHead(200, {'Content-Type': 'text/
html'}); res.end('Hello World!');
}).listen(8080);

console.log("Server running on port 8080!!");


console.log(“..”);

9. Initialize the folder as a node project using the npm init -y command.
10.Install the http package using the npm install http command.
11.Create the Dockerfile and write the following code in it.

FROM node:latest AS builder


WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .

FROM node:slim
WORKDIR /app
COPY --from=builder /app .
CMD ["node","hello.js"]
EXPOSE 8080

12.Build the docker image using the “docker build -t <image_name> .” command
and then run the container using the docker run command.
6. Tag the image using the docker tag command and then push it to docker hub using
the docker push command.
4.Result/Output/Writing Summary:

We can access the node application in our host machine by entering


“http://localhost:8080/” in the browser.

Learning outcomes (What I have learnt):

1. I have learnt the concept of containerization.

2. I have learnt to configure Docker to work with different environments.

3. I have learnt how to build docker images using Dockerfile.

4. I have learnt the purpose of Dockerfile and its advantages.

5. I have learnt how Dockerfile can help in creating CI/CD pipelines.


Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.

2.

3.

You might also like