0% found this document useful (0 votes)
7 views91 pages

Cloud Computing Manual (Final)

The document outlines the vision and mission of the Department of Computer Science Engineering at Rohini College, emphasizing quality education and research in emerging technologies. It includes a list of experiments for a Cloud Computing course, detailing procedures for installing software and creating applications using various tools like VirtualBox, Google App Engine, and CloudSim. The document serves as a guide for students to gain practical experience in cloud computing and software development.

Uploaded by

prince861076
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views91 pages

Cloud Computing Manual (Final)

The document outlines the vision and mission of the Department of Computer Science Engineering at Rohini College, emphasizing quality education and research in emerging technologies. It includes a list of experiments for a Cloud Computing course, detailing procedures for installing software and creating applications using various tools like VirtualBox, Google App Engine, and CloudSim. The document serves as a guide for students to gain practical experience in cloud computing and software development.

Uploaded by

prince861076
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

lOMoARcPSD|27969559

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

CCS335-CLOUD COMPUTING

NAME :

REGISTER NUMBER :

DEPARTMENT : CSE

YEAR / SEMESTER : III/S6

REGULATION : 2021

ACADEMIC YEAR : 2025-2026(EVEN)


lOMoARcPSD|27969559

ROHINI COLLEGE OF ENGINEERING AND TECHNOLOGY

VISION

 To be a Centre of excellence in engineering and technology.


 To produce technocrats who are technically competent, ethically strong for
advancement of the society.

MISSION
 To provide quality education in emerging technologies in accordance with industrial
trends.
 To build good research capabilities and support new innovations.

DEPARTMENT OF CSE

VISION

To create young software professionals to compete the global challenges in the field of computer
science and engineering and be researcher to meet the need of society.

MISSION

 To provide quality education to develop software for real time problem in scientific and
business application for various needs of industry. 
 To provide learning ambience to enhance innovations, problem solving skill, leadership
qualities, team spirit and ethical responsibility to serve the society. 
PEO

 The graduates will be able to design and to adapt modern tools to innovate ideas and
develop computational solution for technological problem.
 The graduates will be able to develop professional skills for employment and understand
the need of lifelong learning for a successful professional career.
 To develop an ability to become successful professional, entrepreneur and urge for

pursuing higher studies.


LIST OF EXPERIMENTS

1. Install Virtual box / VMware Work station with different flavours of


linux or windows OS on top of windows7 or 8.
2. Install a C compiler in the virtual machine created using virtual box
and execute Simple Programs
3. Install Google App Engine. Create hello world app and other simple
web applications using python/java.
4. Use GAE launcher to launch the web applications.

5. Simulate a cloud scenario using CloudSim and run a scheduling


algorithm that is not present in CloudSim.
6. Find a procedure to transfer the files from one virtual machine to
another virtual machine.
7. Install Hadoop single node cluster and run simple applications like
word count.
8. Creating and executing your first container using docker.
9. Run a container from Docker Hub.
TABLE OF CONTENTS

[Link]. DATE EXPERIMENT TITLE MARK SIGN.


S/10
1. Install Virtualbox / VMware Work station
with different flavours of linux or windows
OS on top of windows 7 or 8.
2. Install a C compiler in the virtual machine
created using virtual box and execute
Simple Programs
3. Install Google App Engine. Create hello
world app and other simple web
applications using python/java.
4. Use GAE launcher to launch the web
applications.
5. Simulate a cloud scenario using CloudSim
and run a scheduling algorithm that is not
present in CloudSim.
6. Find a procedure to transfer the files from
one virtual machine to another virtual
machine.
7. Install Hadoop single node cluster and run
simple applications like word count.

8. Creating and Executing your first container


using docker .
9. Run a container from Docker Hub.
INSTALL VIRTUAL BOX/VMWARE WORKSTATION
[Link]
WITH DIFFERENT FLAVOURS OF LINUX OR

DATE: WINDOWS OS ON TOP OF WINDOWS7 OR 8.

AIM:
To Install Virtual box/VMware Workstation with different flavours of linux or windows OS on top of
windows7 or 8 Procedure

Virtual Box installation

1. First we need to download Virtual Box from [Link] downloaded


Virtual Box 5.1.14
2. need to
change anything for our purposes, and can accept the defaults. Before completing the wizard you will get a
warning that the network connection will temporarily be
that would be impacted, like being half-way through downloading a 16GB file be resumed

2. Create an Ubuntu virtual machine

1. Download the latest Ubuntu release from [Link]


downloaded Ubuntu 16.04.1
2. Open Virtual Box and click New

1
3. Type the Name for the virtual machine, like Ubuntu 16. VirtualBox will try to predict the
Type and Version based on the name you enter. Otherwise, select:

Type: Linux
Version: Ubuntu (64-bit)
and click Next.

4. Next we need to specify how much memory to allocate the virtual machine. According to the
Ubuntu system requirements handle it.
Basically the higher you can set the memory without severly impacting your host machine, the
better the performance of the guest machine. If not sure, stick with 2GB.

2
5. On the Hardware screen select Create a virtual hard disk now and click Create
6. Accept the default option VDI for Hard disk file type (or change it if you and click
Next
7. Next we are prompted for Storage on physical hard disk. The options are Dynamically
allocated and Fixed size. use the default of Dynamically allocated. Click Next

8. Choose the hard disk size and storage location. The Ubuntu system requirements recommend
25GB. Remember, we choose Dynamically allocated as our storage option in the last step, so we
allocate it as required,
up to the maximum 25GB we specified. Click Create
9. The wizard will finish and we are returned to the main VirtualBox window. Click Settings

10. In the left pane select Storage, then in the right select the CD icon with the word Empty
beside it.

3
11. Under Attributes click the CD icon (highlighted in the screenshot above) and select
Choose Virtual Optical Disk File and browse to the downloaded file ubuntu-16.04.1- desktop-
[Link]

12. Click OK to close the Settings dialog window. The virtual machine should now be ready
to start.

Install Ubuntu
In VirtualBox your VM should be showing as Powered Off, and the optical drive configured to pointto
the Ubuntu ISO file we downloaded previously.
1. In VirtualBox, select the virtual machine Ubuntu 16 and click Start. VirtualBox will launcha
new window with the vm and boot from the iso.

4
2. Click Install Ubuntu

3. Select Download updates while installing Ubuntu and click Continue


4. On the next screen accept the default of Erase disk and install Ubuntu and click Install Now

5. You will be prompted with a warning saying the changes will be written to disk. Click
Continue

5
6. Select your timezone and click Continue
7. Select your keyboard layout. I accepted the default of English (US) and click Continue
8. Enter a username and password, then click Continue

9. The Ubuntu installation may take several minutes to run, so have another coffee.

6
10. When the installation is finished you will be prompted to restart. Save and close
anything else you may have open and click Restart Now

11. Now when the vm reboots you may see this message.

7
From the menu select Machine > Settings.

Navigate back into the Storage settings where we previously selected the iso file. If the Ubuntu
iso file is still there, remove it. Otherwise close the Settings window and in the vm press Enter to
proceed.
12. If all went well the VM should boot to the Ubuntu login screen. Enter your password to
continue.

Ubuntu should run normally in the VirtualBox environment. If everything is far too small, you can adjust
the by selecting View > Scale Factor > 200%.
Have fun!

8
Result:
Thus the Virtual box/Oracle Virtual machine has installed Succesfully.

9
[Link] INSTALL A C COMPILER IN THE
VIRTUAL MACHINE AND EXECUTE A
DATE:
SAMPLE PROGRAM.

Aim :

To install a C compiler in the virtual machine and execute a sample program.

Procedure:
step1:

Install the centos or ubuntu in the VMware or Oracle Virtual Machine as per previous commands.

Step 2:
Login into the VM of installed OS.

Step 3:
If it is ubuntu then, for gcc installation
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install gcc-6 gcc-6-base

Step 4:
Write a sample program like
[Link]
#include<iostream.h>
using namespace std;
int main()
{

return 0;
}

10
Step 5:
First we need to compile and link our program. Assuming the source code is saved in a file
[Link], we can do that using GNU C++ compiler g++, for example g++ -Wall -o
welcome [Link] and output can be executed by ./welcome

Result:
Thus the GCC compiler has installed and executed in this sample program successfully.

11
[Link] Install Google App Engine. Create hello world app
and other simple web applications using
DATE:
python/java

Aim:

To install Google App Engine (GAE) and create a Hello World application and simple
web applications using Python / Java.

Procedure:

Step1:

 Login with your G-mail Account.


 Open Google Cloud Console.

12
Step 2:

Step 3:
Click Console.

13
Step 4:
The Google Cloud Platform Dashboard is displayed. Scroll down and select the APIs & Services
option.

Step 5:
Select Library.

14
Step 6:
A search bar appears. Type App Engine in the search bar.

15
Step 7:
Select App Engine Admin API and click on Enable.

Step 8:
Click Activate Cloud Shell in the top left corner and click Continue.

16
Step 9:
The Cloud Shell terminal window appears as shown in the figure.

Step 10:
To open the Python source code, GitHub can be used. The GitHub link is given below.

17
Python GitHub Code Link:
GitHub - GoogleCloudPlatform/python-docs-samples: Code samples used on [Link]

Step 11:
Select code.

Step 12:
After selecting the source code, the repository URL is displayed. Copy the URL.

18
Step 13:

19
Step 14:
Enter the command git clone <copied URL> in the Cloud Shell terminal. Remove .git from the
end of the URL and press Enter.”

Step 15:
Type ls to list out the items.

20
Step 16:
Enter the command cd python-docs-samples to move into the project directory.

Step 17:
Enter the command ls to display the files and folders present inside the python-docs-samples
directory.

Step 18:
Enter the command cd appengine to navigate to the App Engine directory.

21
Step 19: Type ls to list out the items.

Step 20: Enter the command cd standard_python3 to navigate to the directory, and then type ls
to list the items.

Step 21: Enter the command cd hello_world to navigate to the Hello World application
directory.

Step 22: Enter the command ls to display the files. Here, [Link] represents the configuration
file and [Link] represents the source file.

Step 23:
To display the contents of the [Link] source file, use the command cat [Link].

22
Step 24:
The source code of the [Link] file used for the Hello World application is shown below.

Step 25:
Enter the command python3 [Link] to run the Python program. After successful
execution, the application URL is displayed.

23
Step 26:
By clicking the generated URL, the output of the application is displayed in the web browser.

Result:
Google App Engine was successfully installed and configured. A Hello World application
and simple web applications were developed and deployed using Python and Java.

24
[Link] USE GAE LAUNCHER TO LAUNCH THE
WEB APPLICATIONS
DATE:

AIM:
To use GAE launcher to launch the web applications.

PROCEDURE:
Step 1: Install Python 2.7.3 on the system.

25
Step 2:
Install Google App Engine Launcher version 1.9.62 using the link provided below.

[Link]

Step 3:
Select Search → Google App Engine Launcher to open the application.

26
27
Step 4:
Go to the Desktop and create empty folder.

Step 5: The created folder contains no items and is an empty folder.

Step 6:

Go to Google App Engine Launcher. The following window will appear.

28
Step 7: Choose File → Create New Application from the menu.

Step 8: The following dialog box will appear.

Step 9: In the dialog box, enter the Application Name and specify the Parent Directory as the
folder created earlier.

29
Step 10: When the created folder is opened, the configuration file and source code file can be
seen.

Step 11: Select the created App Engine application (it will be highlighted in blue).

Step 12: Select the current App Engine application and click Run.

Step 13: Click Allow Access when prompted.

30
Step 14: The result can be viewed on port number 8080. Open a web browser and type
localhost:8080 in the address bar.

Step 15: The output will be displayed in the web browser.

Result:
Thus the Google App Engine has launched in this sample program agreeably.

31
[Link] SIMULATE A CLOUD SCENARIO USING CLOUDSIM
AND RUN A SCHEDULING ALGORITHM THAT IS NOT
DATE: IN CLOUDSIM

AIM:
Simulate a cloud scenario using cloudsim and run a scheduling algorithm that is not in
Cloudsim.
PROCEDURE:

Step 1: Java Installation

a. Check Java in your system


Verify whether Java is already installed on the system by opening the Command Prompt and
typing java -version. If the Java version details are displayed, Java is installed successfully.

b. If Java is not installed, then download Java


If Java is not found on the system, download the latest Java Development Kit (JDK) from the
official Oracle website and proceed with the installation.

32
c. Install java setup

33
The above address should be copied and the copied address should be pasted in the Edit the
system environment variables window.

d. Set path variable for java.

 Go to the Start button.

 Type Edit the system environment variables in the search box and open it.

34
35
1. Click on Edit the system environment variables and select Environment Variables
in the System Properties window.

2. Select the Edit option to modify the environment variable.

36
3. Click New to add a new environment variable.

37
4. Paste the copied address in the given field and click OK.

Step 2: Download CloudSim and Additional JAR File

a. Download CloudSim 3.0.3

1. Open a web browser and type “CloudSim 3.0.3 zip download” in the search bar.
2. Select a reliable source and download the CloudSim 3.0.3 ZIP file to your system.

38
3. Download the [Link] file and extract it to the desired location on the system.

b. Download Commons math 3 jar file.

1. Open a web browser and type “Commons Math 3” in the Google search bar

39
2. Select the first link from the search results.

40
[Link] and extract the ZIP file.

[Link] the commons-math-4.0 folder from the Downloads directory.

[Link] the first JAR file from the commons-math-4.0 folder.

41
6. Paste the copied JAR file inside the CloudSim jars directory to complete the setup.

42
7. Copy the cloudsim-3.0.3 folder and paste it into the Documents folder for further use.

43
Step 3: Eclipse IDE Installation

a. If java 64 bit installed then download 64 bit Eclipse, otherwise if java 32 bit then download 32
bit Eclipse.

44
45
b. Install Eclipse IDE

Step 4: Run CloudSim in Eclipse.


1. Open Eclipse IDE.

46
2. It will be opening like this.

47
3. Select Create a Java Project.

48
4. Give Project name.

49
5.

 Uncheck the checkbox (remove the tick).

 Click on the Browse button.

50
6. Navigate to the Documents folder and Select cloudsim-3.0.3.

51
7. Click Next.

52
8. Click Finish.

53
8. Expand cloudsim2.
9. Under it, go to examples → [Link].
10. Select the first program listed. It will be displayed in the editor.

Step 9:

 Click on Run.
 Select Proceed to execute the program.

54
Step 10:

The program output will be displayed in the console/output window.

Result:
Thus the cloud scenario using cloudsim and run a scheduling algorithm that is not in
Cloudsim was run successfully.

55
[Link] Find a procedure to transfer the files from one
virtual machine to another virtual machine.
DATE:

AIM:
To find a procedure to transfer the files from one virtual machine to another virtual
machine.

Procedure:

Step 1:
Install ubuntu OS in the VMware or Oracle Virtual Machine as per previouscommands .

Step 2:
Login into the VM of installed OS.

Step 3:
[Link] the Terminal window in the Ubuntu system .

[Link] the package list using the command.

sudo apt update

[Link] the OpenSSH server by typing the command.

sudo apt install openssh-server

56
Step 4:
1. After installing the OpenSSH server, go to the Devices menu in the virtual machine
window.

2. Select Network from the Devices menu.

3. Click on Network Settings.

4. Configure the required network adapter settings.

57
Step 5:
 Type the following command to view the network configuration.

ifconfig

 Press Enter to display the IP address and network interface details of the system.

58
Step 6:
1. Open a web browser in the Windows system.

2. Search for WinSCP.

3. Download the WinSCP setup file from the official website.

4. Run the downloaded setup file and follow the installation instructions.

5. Click Next and then Install to complete the installation.

6. After installation, launch WinSCP from the desktop or start menu.

59
Step 7:
1.A login dialog box will appear.

[Link] the Host Name field, enter the IP address obtained using the ifconfig command.

[Link] the User Name and Password of the Upuntu System.

[Link] on Login to establish the connection.

60
The connection will be established successfully, and the files of the remote Upuntu
System will be displayed in WinSCP.

61
Step 8:
 In WinSCP , locate the required document in the system files panel.
 Drag and drop or copy the document from the local system to the Ubuntu
machine.
 The selected document will be successfully transferred to the Ubuntu System.

62
Step 9:
 Open the Ubuntu system.
 Go to the Files folder in Ubuntu.
 The transferred file can be seen inside the Ubuntu files directory.

Result:
The file was successfully transferred from one virtual machine to another virtual
machine.

63
[Link] Install Hadoop single node cluster and run simple
applications like word count.
DATE:

Aim:
To Install Hadoop single node cluster and run simple Applications like word count.

Steps:

Install Hadoop.

Step1:

Click here to download the Java 8 Package. Save this file in your home directory.

Step2:

Extract the Java tar File.

Command:[Link]

Fig: Hadoop Installation Extracting Java Files

Step3:
Download the Hadoop2.7.3 Package.

Command: wet [Link]


[Link]

Fig: Hadoop Installation Downloading Hadoop


64
Step4:
Extract the Hadoop tar File.

Command: [Link]

Fig: Hadoop Installation Extracting Hadoop Files

65
Step5:Add the Hadoop and Java paths in the bash file (.bashrc). Open. bashrc

file. Now, add Hadoop and Java Path as shown below.

Command:vi .bashrc

Fig: Hadoop Installation Setting Environment Variable

Then, save the bash file and close it.

For applying all these changes to the current Terminal, execute the source command.

Command: [Link]

Fig: Hadoop Installation Refreshing environment variables

To make sure that Java and Hadoop have been properly installed on your system and can be
accessed through the Terminal, execute the java- version and hadoop.

Version commands.

Command: java - version

66
Fig: Hadoop Installation Checking Java Version

Command: hadoop version

Fig: Hadoop Installation Checking Hadoop Version

Step6:

Edit the Hadoop Configuration files.

Command: cdhadoop-2.7.3/etc/hadoop/

Command: ls

67
All the Hadoop configuration files are located in hadoop-2.7.3/etc/hadoop directory as you can
see in the snapshot below:

Fig: Hadoop Installation Hadoop Configuration Files

Step 7:
Open [Link] and edit the property mentioned below inside configuration tag:

[Link] informs Hadoop daemon where NameNode runs in the cluster. It contains
configuration settings of Hadoop core such as I/O settings that are common to HDFS & Map
Reduce.

Command: [Link]

Fig: Hadoop Installation [Link]

1
2 <configuration>
3 <property> 68
<name>[Link]</name>
4 <value>hdfs://localhost:9000</v
5 alue>
</property>
Step8:
Edit [Link] and edit the property mentioned below inside
configurationtag:
[Link] contains configuration settings of HDFS daemons (i.e. NameNode, DataNode,
Secondary NameNode). It also includes the replication factor and block size of HDFS.

Command:[Link]

Fig:Hadoop Installation [Link]

1
2
3
<configuration>
4 <property>
5 <name>[Link]</name>
6 <value>1</value>
7 </property>
<property>
8 <name>[Link]</name>
9 <value>false</value>
10 </property>
</configuration>
11

Step9:

Edit the [Link] file and edit the property mentioned below
Inside configuration tag:

69
[Link] contains configuration settings of MapReduce application like number of JVM
that can run in parallel, the size of the mapper and the reducer process, CPU cores available for a
process, etc.

In some cases, [Link] file is not available. So, we have to create the mapred- [Link]
file using [Link] template.

Command: [Link] [Link]


Command:[Link].

Fig: Hadoop Installation [Link]

1
2
3 <configuration>
4 <property>
5 <name>[Link]</name>
<value>yarn</value>
6 </property>
7 </configuration>

Step 10:

70
Edit [Link] and edit the property mentioned below inside configuration tag:

[Link] contains configuration settings of Resource Manager and Node Manager like
application memory management size, the operation needed on program & algorithm, etc.

Command: [Link]

Fig: Hadoop Installation [Link]

1
2
3 <configuration>
4 <property>
5 <name>[Link]-services</name>
<value>mapreduce_shuffle</value>
6 </property>
7 <property>
8
9 name>
<value>[Link]</value>
1 </property>
0 </configuration>
1

Step11:Edit [Link] add the Java Path as mentioned below:


[Link] contains the environment variables that are used in the script to run
Hadoop like Java home path, etc.

71
Command: vihadoop [Link]

Fig: Hadoop Installation Configuring [Link]

Step12: Go to Hadoop home directory and format the Name Node.

Command: cd

Command: cd hadoop-2.7.3

Command: bin/hadoopnamenode-format

Fig:HadoopInstallation Formatting NameNode

This formats the HDFS via Name Node. This command is only executed for the first time.
Formatting the file system means initializing the directory specified by the [Link]
variable.

Never format, up and running Hadoop file system. You will lose all your data stored in the
HDFS.

Step13:
Once the Name Node is formatted, go to hadoop-2.7.3/sbin directory and start all the
daemons.

72
Command:cdhadoop-2.7.3/sbin

Either you can start all daemons with a single command or do it individually.

Command:./[Link]

The above command is a combination of [Link], [Link] & mr-jobhistory- [Link]

Or you can run all the services individually as below:

Start Name Node:

The Name Node is the center piece of an HDFS file system. It keeps the directory tree of all files
stored in the HDFS and tracks all the file stored across the cluster.

Command:./[Link] start name node

73
Fig:Hadoop Installation Starting Name Node

Start Data Node:

On startup, a Data Node connects to the Name node and it responds to the requests from the
Name node for different operations.

Command:./[Link] start data node

Fig:HadoopInstallation StartingDataNode

Start Resource Manager:

Resource Manager is the master that arbitrates all the available cluster resources and thus helps
in managing the distributed applications running on the YARN system. Its work is to manage
each Node Managers and the each Application Master.

Command:./[Link] start resource manager

74
Fig: Hadoop Installation Starting Resource Manager

Start Node Manager:

The Node Manager in each machine framework is the agent which is responsible for managing
containers, monitoring their resource usage and reporting the same to the Resource Manager.

Command:./[Link] start node manager

Fig: Hadoop Installation Starting Node Manager

Start Job History Server:

Job History Server is responsible for servicing all job history related requests from client.

Command:./[Link] starthistoryserver

Step14:

To check that all the Hadoop services are up and running, run the below command.

75
Command:jps

Fig: Hadoop Installation Checking Daemons

Step15:
Now open the Mozillabrowser and go
To localhost:50070/[Link] to check the Name Node interface.

Fig:HadoopInstallation StartingWebUI

Congratulations, you have successfully installed a single node Hadoop cluster

Result:

Thus the Hadoop one cluster was installed and simple applications executed successfully.

76
[Link] Creating And Executing Your First Container
Using Docker.
DATE:

AIM:

To create and execute a container using docker..

STEP 1 : Installing Docker on the System

To begin, you will need to install Docker on your system.


Docker provides installers for Windows, macOS, and various flavors of Linux, making it
accessible to a wide range of users.
Below are the commands you can use to install Docker on Ubuntu:

1. sudo apt update


2. sudo apt install apt-transport-https ca-certificates curl software-properties-common
3. curl -fsSL [Link] | sudo apt-key add -
4. sudo add-apt-repository "deb [arch=amd64] [Link]
$(lsb_release -cs) stable"
5. sudo apt update
6. sudo apt install docker-ce

Once the installation is complete, you can verify it by checking the Docker version and making
sure the Docker daemon is running.

STEP:2
Verifying the Installation and Accessing the Docker CLI

For those using the Ubuntu operating system, you can verify the Docker installation by running
the following command:

[Link] --version
[Link] systemctl status docker

With Docker successfully installed, you can now access the Docker command-line interface (CLI)
to start creating and managing containers.

The CLI provides a set of commands for interacting with Docker, allowing you to build, run, and
manage containers with ease.
77
STEP 3 :
Crafting Your First Dockerfile

Some of the key concepts in Docker revolve around creating a Dockerfile, which is a text
document that contains all the commands a user could call on the command line to assemble an
image.
The Docker file contains all the information Docker needs to build the image. Let’s take a look at
how to define a simple Dockerfile and some best practices for writing it.

STEP 4 :
Defining a Simple Dockerfile
First, Let’s start by creating a basic Dockerfile.
In this example, we’ll create a Dockerfile that simply prints “Hello,World!” when run as a
container.

1. FROM alpine
2. CMD echo "Hello, World!"

When defining a simple Dockefile ,it is important to keep it as minimal as possible.


Only include the necessary dependencies and commands required for your application to run
within the container.
This helps to keep the image size small and reduces the attack surface, making it more secure.

STEP 5 :
Best Practices for Writing Dockerfiles
Dockerfiles should follow best practices to ensure consistency, maintainability, and reusability.
One of the best practices is to use the official base images from Docker Hub, as they are well-
maintained and regularly updated. It’s also important to use specific versions of the base images to
avoid unexpected changes.
[Link] node:14
[Link] . /app
[Link] /app
[Link] npm install
[Link] ["npm", "start"]

Best practices for writing Dockerfiles also include using a .docker ignore file to specify files and
directories to exclude from the context when building the image.
This helps to reduce the build context and improve build performance.

65
Some additional best practices for writing Dockerfiles include avoiding running commands as
root, using multi-stage builds for smaller images, and using environment variables for
configuration.

STEP 6:
Building and Running Your Container.

To build and run your Docker container, you will need to follow a few simple steps.

First, you will need to build the Docker image from your Dockerfile.
Once the image is built, you can run your container using the Docker run command. In this
section, we will walk through each step in detail.

Building the Docker Image from Your Dockerfile

To build the Docker image from your Dockerfile, you will need to navigate to the directory where
your Dockerfile is located and run the following command:
docker build -t your-image-name .
This command will build the Docker image using the instructions specified in your Dockerfile.
Once the build process is complete, you will have a new Docker image ready for use.

Running Your Docker Container


To run your Docker container, you will need to use the Docker run command followed by the
name of the image you want to run.
For example:
docker run your-image-name
Running this command will start a new container based on the specified image.
Depending on your application, you may need to specify additional options for the docker run
command,
Such as port bindings or environment variables.
docker run -p 8080:80 your-image-name
Your Docker container is now up and running, ready to serve your application to the world.

Managing Your Docker Container


Unlike traditional virtual machines, where you need to manually install and configure software,
Docker containers are designed to be easily managed and [Link] your Docker
containers.

Monitoring Container Performance

With Docker, you can easily monitor the performance of your containers using built-in commands.
By running docker stats , you can view real-time CPU, memory, and network usage for all running
containers.
This can help you identify any resource bottlenecks and optimize your container performance.
66
Stopping, Starting, and Removing Containers

The Docker CLI provides simple commands for stopping, starting, and removing containers.

The command
docker stop [container_name]

will gracefully stop a running container, while

docker start [container_name]


will restart a stopped container.

To remove a container entirely, use the command

docker rm [container_name]

Additionally, you can use the docker ps command to list all running containers, and docker ps -a to see all
containers, including those that are stopped.

This gives you full visibility and control over your containers.

RESULT:
Thus a container is created and executed in a docker successfully.

67
[Link] Run a container from DockerHub.

DATE:

AIM:
To run and execute a container from Docker Hub using Docker.

PROCEDURE:

Step1: Get the sample application. If you have it, you can clone the repository for the sample
application. ...
Step2: Explore the Docker file....
Step 3: Build your first image. ...
Step 4: Run your container. ...
Step 5: Verify that your container is running.

Step1: Signup for a Docker account.


Start by creating a Docker ID.

A Docker ID grants you access to Docker Hub repositories and allows you to explore images that are
available from the community and verified publishers. You’ll also need a Docker ID to share images on
Docker Hub.

Step2: Create your first repository

To create a repository:

1. Sign in to Docker Hub.


2. Select Create a Repository on the Docker Hub welcome page.
3. Name it <your-username>/my-private-repo.
4. Set the visibility to Private.
5. Select Create.

68
You’ve created your first repository.

Step 3: Download and install Docker Desktop


You need to download Docker Desktop to build, push, and pull container images.

1. Download and install Docker Desktop.

2. Sign in to Docker Desktop using the Docker ID you created in step one.

Step 4:
Go to Visual Studio code Application and create your Docker File.

[Link]

FROM python:3.8-slim
WORKDIR /app
COPY . /app
CMD ["python","[Link]"]

[Link]
print ("hello")

69
After creating build and run your Docker File.

Step 5: Docker Login

 Type the command docker login.

 A link will appear in the terminal.

70
 Copy the link and paste it into the browser.

 A dialog box will appear.

 Enter the one-time confirmation code to complete the login.

This message will be displayed on your terminal.

Step 6: Push a container image to Docker Hub

71
Go to your Docker Hub repository and verify that the container image has been successfully added.

Step 7: Pull a container image from Docker Hub.


Create new Directory and pull your image into that directory.

72
To verify, Type ls command

To execute the program type the command,

docker run project name

Go to Docker Desktop on your local system. The pulled image will be available there.

73
Result:
Thus the Run a container from Docker Hub is run successfully and output is verified.

74

You might also like