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

UNIVERSITY OF PETROLEUM AND ENERGY STUDIES,

DEHRADUN

“CONTAINER ORCHESTRATION
&
INFRASTRUCTURE AUTOMATION”

LAB FILE

Submitted to
MR. ABHIRUP KHANNA
ASSISTANT PROFESSOR
SCHOOL OF COMPUTER SCIENCE

By:
ANANT GARG
500084917
R2142201709
B3-CCVT NON-HONS

1|Page
Lab Experiment: 1................................................................................................................................... 3
“Installing Docker on Linux” ................................................................................................................ 3
Lab Experiment: 2................................................................................................................................... 5
“Installing Docker in windows” ........................................................................................................... 5
Lab Experiment: 3................................................................................................................................... 9
“Working with Docker: Images” ......................................................................................................... 9
Lab Experiment: 4 ................................................................................................................................ 11
“Working with Docker File” ............................................................................................................... 11
Lab Experiment: 5................................................................................................................................. 15
“Docker Public Repository” ............................................................................................................... 15
Lab Experiment: 6................................................................................................................................. 18
“Managing Ports in Docker” ............................................................................................................. 18
Lab Experiment: 7................................................................................................................................. 21
“Docker private registry” .................................................................................................................. 21
Lab Experiment: 8................................................................................................................................. 23
Docker-Building a Web Server Docker File ........................................................................................ 23
Lab Experiment: 9................................................................................................................................. 25
“Docker: Container linking” .............................................................................................................. 25
Lab Experiment: 10............................................................................................................................... 27
“Installing & Starting in this MiniKube” ............................................................................................ 27

2|Page
Lab Experiment: 1
“Installing Docker on Linux”

Step 1: To install docker on ubuntu simply run the following command: -


sudo snap install docker
Or
sudo apt install docker.io

Fig 1.1(Installing docker)

Step 2: Verify Docker Installation


To inspect whether docker is installed and is in active state or not, execute the following
commands: -
sudo docker version

Fig 1.2(Checking docker version)

sudo systemctl status docker

3|Page
Fig 1.3(Docker status active)

Step 3: Run a Docker Container


Command: sudo docker run hello-world
In this command the ‘hello-world’ image would be fetched from docker hub since it is not
present locally as of now and as soon as the ‘hello-world’ image is fetched, a container
would be created from it.

Fig 1.4(Running a container of ‘Hello-world’ image)

4|Page
Lab Experiment: 2
“Installing Docker in windows”
Step1: -Download Docker Installer Using this link
https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe

Fig 2.1 (Windows Docker Desktop Installer)

Step 2: - Open the installer


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. If your system only supports one of the two
options, you will not be able to select which backend to use.

Fig 2.2 (Configuration settings)

5|Page
Step 3: - Once you click ok. The Unpacking of Files starts

Fig 2.2 (Unpacking files)

Step 4: - Docker is successfully Installed. Click close and restart

Fig 2.4 (Installation finished)

6|Page
Step 5: - After Updating. Service Agreement window will open accept the
Agreement

Fig 2.5 (Service Agreement Window)

Step 6: - Install WSL 2 Linux Kernel using the link. After installation Click restart.
https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

Fig 2.6 (Click on restart)

7|Page
Step 7: - Your Docker is Successfully installed.

Fig 2.7 (Docker successfully installed)

8|Page
Lab Experiment: 3
“Working with Docker: Images”

Displaying Docker Images


Syntax: docker images

This command is used to display all the images currently installed in system

Return value: The output will return the list of images on the system

Fig 3.1(Images currently present)

Syntax: docker images -q

Returns docker images id

Fiig 3.2(Running docker images –q command)

Downloading Docker Images


Syntax: docker run image

Here image is the name of image you want to run in container

Return: The output will run command in desired container

Fig 3.4(Pulling centos images from docker hub)

9|Page
Docker Inspect
Syntax: docker inspect Repository

Repository is the name of the image

Return: The output will show details information on the image

Fig 3.5(Docker inspect command)

Removing Docker Images


Syntax: docker rmi image_id -f

Image_id is the id of the desired image

Return: Image id of the removed image

Fig 3.6(Removing the centos image)

10 | P a g e
Lab Experiment: 4
“Working with Docker File”

Part 1: - Creating docker file which give output Image Create when container is
initiated
Step 1: -create docker file with command sudo vim Dockerfile

Fig 4.1(Creating a Dockerfile)

FROM ubuntu

MAINTAINER anantgargin@gmail.com

RUN apt-get update

RUN apt-get install -y nginx

CMD [“echo”,” Image Created

Fig 4.2(Contents of the dockerfile)

Step 2: - Use Command “docker build” for making docker image using Docker file

11 | P a g e
Fig 4.3(Building an image from the dockerfile)

Step 3: -Docker image is successfully created now run docker image

Fig 4.4(Creating a container from the image built from the Dockerfile)

Part 2: - Creating a docker file whose container will evoke java program when
initialized
Step 1: - Create java file
class Hello{

public static void main(String[] args){

System.out.println("This is Java app running using Docker");

Fig 4.5 (Creating java file)

12 | P a g e
Fig 4.6 (Content of “hello.java”)

Step 2: -Create the docker file

Fig 4.7 (Creating dockerfile)

FROM openjdk:11

COPY . var/www/java

WORKDIR /var/www/java

RUN javac Hello.java

CMD [“java” , “Hello”]

Fig 4.8 (Content of Dockerfile)

13 | P a g e
Step 3: -Create the docker image from docker file

Fig 4.9 (Building docker image form dockerfile)

Fig 4.10 (Successfully created image)

Step 4: -Run the Docker Image

Fig 4.11 (Running the docker image)

14 | P a g e
Lab Experiment: 5
“Docker Public Repository”

Step 1: -Log into docker hub and create your repository. This is the repository where your
image will be stored.

Fig 5.1(Logging in docker hub)

Step 2: - Click on the button “Create a Repository” on the above screen and create a
repository. Make sure the visibility of repository is public. Once the repository is created,
make a note of pull command which is attached to the repository.

15 | P a g e
Fig 5.2(Creating a public repository in docker hub)

Fig 5.3(Repository created)

Step 3: - Issue the docker login command to login into the docker hub repository from the
command prompt. The docker login command will prompt you for the username and
password to docker hub repository

Fig 5.4(signing in our docker account from local host)

Step 4: - Once the image has been tagged it’s now time to push the image to the Docker
Hub repository. We cad do this using docker push command

Fig 5.5(Tagging the image)

16 | P a g e
Fig 5.6(Pushing the tagged image into the public repository that we created online)

Step 5: -Successfully pushed docker image

Fig 5.7(Image pushed into repository successfully)

Step 6: -Successfully pulled docker image in docker repository

Fig 5.8(Pulling the image from our repository)

17 | P a g e
Lab Experiment: 6
“Managing Ports in Docker”

Step 1: - Log in into the docker hub

Fig 6.1 (Dockerhub main page)

Step 2: -Now, let’s browse and find the Jenkins image.

Fig 6.2 (Jenkins official image)

18 | P a g e
Step 3: - Pull the Jenkins to your Ubuntu server using “docker pull jenkins” from docker hub

Fig 6.3 (Pulling Jenkins image)

Step4: - use Docker inspect command to inspect the docker image “docker inspect
jenkins/jenkins:latest”

Fig 6.4 (Running inspect command on Jenkins container)

19 | P a g e
Fig 6.5 (Here you can see that Exposed Ports are 8080 and 50000)

Step 5: - run the command to run the Jenkins on container with 8080 port open
Command: - docker run -p 8080:8080 -p 50000:50000 --name=jenk -d jenkins/jenkins
/bin/bash

Fig 6.6 (Running Jenkins on container with port 8080 open)

And you can access your Jenkins by going to your browser and going to localhost:8080

Fig 6.7 (Accessing Jenkins at port 8080)

20 | P a g e
Lab Experiment: 7
“Docker private registry”
Objectives: -
• Create a private registry
• Tag the previously created image
• Push the image in the private registry
• Delete the local Image
• Pull the image from private registry

Step 1: - Pull the private registry image with port open 5000

Command: - docker run -d -p 5000:5000 –name registry registry

Fig 7.1 (Pulling private registry image)

Step 2: - Tag the local image which you want

Fig 7.2 (Tagging local image ‘hello-world’)

21 | P a g e
Step 3: - Now push the new tagged file to the registry

Fig 7.3 (Pushing the tagged image to the registry)

Step 4: - Remove the tagged image from the docker host

Fig 7.4 (Remove tagged image)

Step 5: - Now use the private registry to pull the image

Fig 7.5 (‘Pulling localhost:5000/hello-world’ using private registry)

22 | P a g e
Lab Experiment: 8
Docker-Building a Web Server Docker File

Step 1: - Write the docker file for the Web Server

Fig 8.1 (Write dockerfile)

Step 2: - Build the docker image using the docker build command

Command = “docker build -t lab8:latest”

Fig 8.2(building image mywebserver)

23 | P a g e
Fig 8.3 (Image build successful)

Step 3: - Now Run the web server that have been build

Command = “ docker run -d -p 80:80 lab8:latest ”

Step 4: - Now go to the IP of your device with port 80 e.g. 192.168.0.28:80

Fig 8.5 (Apache webserver homepage accessible at port 80)

24 | P a g e
Lab Experiment: 9
“Docker: Container linking”

Objectives: -
• Link multiple containers.
• Step by step process of linking containers using link flag

Steps: -
1) Download the Jenkins image, if it is not already present, using pull command

Fig 9.1(Downloading jenkins image)

2) Once the image is available, run the container, but this time, you can specify a name to the
container by using the name option. This will be our source container.

Fig 9.2(Running the jenkins container)

25 | P a g e
3) Next, it is time to launch the destination container, but this time, we will link it with our
source container. For our destination container, we will use the standard Ubuntu image.

Fig 9.3(specifying the source and destination containers)

4) Now, attach to the receiving container.

Fig 9.4(Attaching the receiving container)

26 | P a g e
Lab Experiment: 10
“Installing & Starting in this MiniKube”

Run the curl command below to download a copy of the MiniKube binary on your machine
(minikube-linux-amd64).

Fig1(shows the installation of curl)

In the same directory where the binary was downloaded, run the followingcommand to install the
MiniKube binary (minikube-linux-amd64) to the appropriate location (/usr/local/bin/minikube).

Fig2(tells the installation of minikube)

27 | P a g e
Lastly, run the below command to start MiniKube using the installed binary and Run the following
command to get all pods running in all namespaces (-A) in the cluster.

Fig3(Start minikube and get all pods)

Run the following kubectl command to create a deployment named httpd using the latest image
(httpd:latest).

Fig4(run kubectl commands)

28 | P a g e
Run the kubectl expose command below to expose your deployment to the outside world with the
standard port 80 using a NodePort service and Note down the URL like in the output below, as you’ll
need it to access your web.

Fig5(get url)

Finally it is shown on web.

Fig6(get result)

29 | P a g e

You might also like