devopsfile practicals file
devopsfile practicals file
Practical File
BACHELOR OF TECHNOLOGY
Information Technology
5 Install Docker 9
12 Install Jenkins 21
Step 2: Click the download link for Windows and allow the download to complete.
1
Figure 1.3: Installation in progress
2
2 Create Account on GITHUB
Step 1: Go to github.com.
3
3 Create Repository on GIT/GITHUB
Step 4: Go to github.com and login your account.
5
Step 8: You have successfully created a repository.
6
4 Create, Merge and Delete Branch
CREATE BRANCH:
MERGE BRANCH:
7
DELETE BRANCH:
Step 1: Go to branches.
8
5 Install Docker
Docker is an open-source project for automating the deployment of applications as portable, self
sufficient containers that can run on the cloud or on-premises. Following are the steps to install
docker:
Step 9: Double-click Docker Desktop Installer.exe to run the installer. If you haven’t already downloaded
the installer (Docker Desktop Installer.exe), you can get it from Docker Hub. It typically down-
loads to your Downloads folder, or you can run it from the recent downloads bar at the bottom
of your web browser.
Step 10: When prompted, ensure the Use WSL 2 instead of Hyper-V option on the Configuration page is
selected or not depending on your choice of backend.
Step 11: Follow the instructions on the installation wizard to authorize the installer and proceed with the
install.
9
Step 12: When the installation is successful, click Close to complete the installation process.
Step 13: If your admin account is different to your user account, you must add the user to the docker-users
group. Run Computer Management as an administrator and navigate to Local Users and Groups
> Groups > docker-users. Right-click to add the user to the group. Log out and log back in for
the changes to take effect.
11
Step 17: Start the Container:
Let’s start the container and see what happens.
Now visit http://localhost with your browser. You will see the default “Welcome to nginx!” page.
We are now running an nginx container.
12
7 Deploy Apache Web Server Image 0n Docker
Apache web server is popular open source http web server tool which is widely used for deployment
of webpages. It can be installed in any operating system. We can create any Apache web server
image in two ways.
Step 18: Download the Docker image, which contains Apache called httpd, by running the docker pull
command below. This command will download or pull the Apache image from the Docker
registry, as shown below.
Step 19: Next, confirm you’ve downloaded the image by running the docker images command below to
list all images available on your computer.
Step 20: Invoke the docker run command to create a new container based on your downloaded Apache
Docker image.
Step 21: Once the Apache container is running, verify if you can access the Apache web interface by
navigating to Public-Ip-address:80 using your web browser. If you can see the same message, as
you can see below, then you’ve successfully started your Apache Docker container.
13
Figure 7.4: Apache Container
Step 22: Finally, stop the container if you don’t need it running anymore by running the docker stop
command below. This command will gracefully stop the container instance.
14
8 Create Custom Page Using Web Server
Step 23: Start the Container:
Let’s start the Nginx container and see what happens.
Now visit http://localhost with your browser. You will see the default “Welcome to nginx!” page.
We are now running an nginx container.
15
Step 25: Create an Image From a Container:
So at this point, we’ve updated the contents of a running container and as long as we keep that
container around, we don’t need to do anything.
However, we want to know how to save this container as an image so we can make other containers
based on this one. The Docker commands to do this are quite simple.
To save a Docker container, we just need to use the docker commit command like this:
16
9 Create Custom Image
In order to run your application in a docker container, a customized docker image is created.
This customized docker image includes instructions that install specific packages and copy the
code into the docker container. This guide describes the basic steps to create a custom docker
image.
Step 26: First we have to create a base container. The following command will create a base container
if the nginx version is latest otherwise it will automatically pull latest version of nginx from
DockerHub:
Step 27: Now we can see that our container is running using the docker ps -a command:
Step 28: Then we have to create a commit for the running container to save it as an image.
Step 29: Then we see our images list. You can see there is a new image and it does not have a repository
or tag, but it exists. This is an image created from the running container.
17
Figure 9.4: Image list
Step 30: When we made the commit, it created an image without a tag or name. You’ll see an image
listed with ¡none¿ as both the ID and name.Using docker tag, we can name the image we just
created.
Step 31: .Now, if you issue the command docker images, you’ll see your new image with the name my-
customimg.
18
10 Push Custom Image to Docker hub
By pushing an image to the Docker hub registry, we can create an instance of an image in which
a particular type of software and applications are pre-installed and can be pulled again whenever
you want to work on that particular type of image or applications and run that kind of virtual
machine.
Step 32: First login to Docker Hub using your username and password when prompted. Use following
command: docker login -u <username>
Step 35: Add Additional Tags to Your Docker Image You often want to include tags like version in addition
to the latest tag. To add a version tag you write the following commands:
19
11 Use Persistent Storage with Docker
In docker, the persistent storage is dealt with the volume concept. Persistent storage is means
when we are stopping or removing the container the data should be persistent. It will not delete
automatically once the docker container is not available. We can define the persistent storage
layer while launching the docker container. Once it will define, the actual data will be store
on the external storage layer which is not a part of the docker environment. The storage layer
will be on the host machine, remote machine, on the cloud, etc. Before directly going to the
docker persistent storage, we need to first understand the storage layer availability on the docker
platform. It will help to understand the storage layer concept.
We are having the list of docker images. The docker images are available on the docker hub.
If we need to create our own images then we can also build a new or own image. Please note,
while creating the new image, we need to choose the respective base image like centos, Ubuntu,
windows, etc. Once the image is ready, we can run the container in the docker. If we are normally
running the container without any storage definition then the docker data is in a volatile state. In
the docker, there are three different ways that the data will be store. 1. bind mounts 2. volumes
3. in-memory storage (tmpfs)
Bind mounts: The bind mounts are a very older method to mount the file or the directory to the
docker container. The bind mount is having limited functionality as compared to the volume.
When we are using the bind mount method, we are using the local file or the local directory to
the docker container. We need to define the complete path of the local file or the local directory
of the local machine into the docker container. While working with the bind mounts, we need to
rely on the local machine file structure. We need to follow the set of rules and regulations which
is imposed on the local system.
Volumes: The volume storage is also known as the persistent data storage layer of the docker.
The default path for the docker volume is /var/lib/docker/volumes. Whenever we are creating
or associating the volume to the docker container. The volume will by default store on the
“/var/lib/docker/volumes” path. Volume is very easier to mount or for the migration. If we are
deleting the docker container but the volume is still present on the storage layer. Then the same
volume we can use for the next or the different docker container. It will use the same data which
was previously used by the older container.
In-memory storage (temporary storage file): When we are launching the docker container without
defining the storage layer like mount or volume. The docker container will run under the in-
memory storage file system. It will store the data temporarily. Once we are deleting or stopping
the respective docker container the data will vanish. The working data is not present in it. We
need to rerun or load the data one more time if we need to work on the same docker container.
In the docker environment, we are able to add persistent storage to the docker image.
20
12 Install Jenkins
Jenkins is an open-source automation server developers can use to automate building, testing,
and deploying applications. It is available on a variety of systems, including Windows, Linux,
Unix, and macOS. Steps to install Jenkins:
Step 36: Browse to the official Jenkins download page. Under the Downloading Jenkins section is a list of
installers for the long-term support (LTS) version of Jenkins. Click the Windows link to begin
the download.
Step 37: Once the download is complete, run the jenkins.msi installation file.
21
Step 39: Select the install destination folder and click Next to continue.
Step 40: Under the Run service as a local or domain user option, enter the domain username and password
for the user account you want to run Jenkins with or go for the localsystem option. Then click
Next to proceed.
22
Step 41: Enter the port number you want Jenkins to run on. Click Test Port to check if the selected port
is available, then click Next to continue.
Step 42: Select the directory where Java is installed on your system and click Next to proceed.
23
Step 43: Select the features you want to install with Jenkins and click Next to continue.
24
Step 45: Once the installation is complete, click Finish to exit the install wizard.
25
13 Create Job on Jenkins
Steps to create a job on Jenkins:
Step 47: In the next screen, enter the Item name, in this case we have named it Helloworld. Choose the
‘Freestyle project option’
26
Step 48: The following screen will come up in which you can specify the details of the job
Step 49: We need to specify the location of files which need to be built. In this example, we will assume
that a local git repository(E:) has been setup which contains a ‘HelloWorld.java’ file. Hence scroll
down and click on the Git option and enter the URL of the local git repository
27
Step 50: Now go to the Build section and click on Add build step → Execute Windows batch command
Step 51: In the command window, enter the following commands and then click on the Save button. Javac
HelloWorld.java Java HelloWorld
28
Step 52: Once saved, you can click on the Build Now option to see if you have successfully defined the job.
Step 53: Once the build is scheduled, it will run. The following Build history section shows that a build
is in progress.
29
Step 54: Once the build is completed, a status of the build will show if the build was successful or not. In
our case, the following build has been executed successfully. Click on the 1 in the Build history
to bring up the details of the build.
Step 55: Click on the Console Output link to see the details of the build.
31
14 Integrate Jenkins With Git/Github
Step 56: Create a Jenkins job, You now need to create a Jenkins job. To do so, click New Item (1). Or,
if it’s a clean install, click on create new jobs (2).
Step 57: Use a GitHub Repository Scroll down a bit more and you’ll see the Pipeline section, where we’ll
tell Jenkins to use the GitHub repo as the source. In the Definition dropdown, choose Pipeline
script from SCM to configure the repo.
Step 59: Add a Webhook in Github Now, go to the GitHub project because it’s time to configure the
webhook so that GitHub can trigger the Jenkins job after every push in the repo. In your
project, click on the Settings (1) tab, then click Webhooks (2) from the left panel. Now, click on
the Add webhook (3) button at the right. Here’s a screenshot for reference:
33
Step 60: Now go to the Build section and click on Add build step → Execute shell
34
Step 62: Change Something in the GitHub Repo. You finished the integration with GitHub in the previous
step. But because you and I are good citizens, let’s make sure that this integration works fully.
So, go to the GitHub repository and change something, commit, and push. In my case, I added a
new stage in the Jenkins pipeline to include more tests. Wait for a few seconds, and you should
see another successful run of the job. If you go the logs for the second time the job ran, you’ll
notice something different at the beginning of the logs saying that GitHub started it, along with
the username:
35