Training Notes
Training Notes
File->open->r/w->close(freed)
1)open
2)Read or write
3)Close
Mode Description
r(read) File is exist read
File Open:
f = open("demofile.txt")
read() file_content=file1.read()
file1=open(“filename”,”r”) print(file_content)
try: try:
file1=open(“filename”,”r”)
file1=open("sample.txt","r") read_content=file1.read()
read_content=file1.read() print(read_content)
file1.close()
print(read_content)
file1.close()
except:
file1.write("File is wriiten when not exist") =>File Created and content is written
filer=open("sample.txt","r")
content=filer.read()
print(content)
filers=open("myfile.txt","r")
content=filers.read()
print(content)
filer=open("sample.txt","r")
content=filer.read()
print(content)
filer.close()
Append:
file1.write("File is written when not exist") =>File Created and content is written
filer=open("sample.txt","r")
content=filer.read()
print(content)
filer.close()
filers=open("myfile.txt","r")
content=filers.read()
print(content)
filers.close()
df=pd.read_csv("data.csv")
print(df)
print(df.head())
print(df.tail())
print("Sum:",df.sum())=> dtype:float64
print("Mean:",df.mean())=>datatype:float64
print(df.loc[:,"Pulse"])
Configure Git
Steps
1. Open the command line
2. Set your username using git config --global user.name "Your Name"
3. Set your email address using git config --global user.email
"your_email@example.com"
4. Verify your configuration by displaying
$ git config --get user.name
git config --get user.email
Tracked Untracked
• managed by the repository • New or modified files that Git
• Status checked when is not yet tracking, meaning
immediately cloned they won't be included in
$ git status commits unless explicitly
On branch main added.
Your branch is up to date with • Untracked→Tracked
'origin/main'. $ git status
On branch main
nothing to commit, working Your branch is up to date with
tree clean 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to
unstage)
new file: new
$ git pull
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (3/3), 993 bytes | 43.00 KiB/s, done.
From https://github.com/ervishnucs/training
5b3fdf6..5f41040 main -> origin/main
Updating 5b3fdf6..5f41040
Fast-forward
new1 | 1 +
1 file changed, 1 insertion(+)
create mode 100644 new1
Initialising Git Repo with working Directory
1. git init →Initialise the repo
2. git add file name
3. git commit -m”new changes”
4. git remote -v → If the Repo URL presents here no need to add or set
Day: 4
2)pwd
• print working directory
• This command in linux is used to display the path of current working
directory inside the terminal
3)cd
It is used to change the current directory to the specified folder inside the
terminal
4)touch file_name_with_extension
Used to create file without content
5)cat
Used to read the content of one or more file c
Cat >>
Copying content from one file to another file
6)mk dir
used to make new directory
7)Cd~-
Go to next directory
8)cd..
Go to previous directory
9)ls
List all available file in directory
ls -l
Permissions ,timelapse and owner of file is shown
ls -s
Used to show the all the hidden file in directory
ls -a
Used to show all files including hidden files, Permissions ,timelapse and owner
of file is shown
ls -S
Sort the all file in directory with respect to files
10)cp
It is used to copy files directly from one location to another from inside the
terminal
cp [args,filename]
11)mv
Move files and directory from one to another directory
→mv file_name destination_path
Move a file or rename a file
→mv curr_file_name new_file_name
12)rm
remove the file it is non-empty & cause data loss
13)rm dir
used to remove empty directories in the file systes
if files in the directory is not empty and rm dir is called then it throws error
14)grep
The grep command in linux search trough a specified file and prints all lines
that match a given word or pattern.
1. Case insensitive search
The -i option enables to search for a string case insensitively in the given file. It
matches the words like “UNIX”, “Unix”, “unix”.
grep -i "UNix" geekfile.txt
Output:
Output:
Displaying the count number of the matches
3. Display the File Names that Matches the Pattern Using grep
We can just display the files that contains the given string/pattern.
grep -l "unix" *
or
grep -l "unix" f1.txt f2.txt f3.xt f4.txt
Output:
Output:
Output:
Output:
Output:
15)head
print the first 10 lines of the content in file also you can specify number of lined
to be shown
head -n number filename
16)tail
print the last 10 lines of the content in file also you can specify number of lined
to be shown
17)history
used to view the history of all the commands previously executed
18)optional feature
• FSHS describes directory structure and it’s content in linux or linux like OS.
• It explains where files and directory should be located what it should contain
ls -l / →shows file system
→Root Directory
• Linux uses a tree-like structure, starting from the root (/) directory. Everything in Linux
(files, directories, devices) is represented as a file.
• It is primary hierarchy of all file and root directory of the entire systems.
• Every single file start from root directory
/ → Root directory: The starting point of the Linux filesystem.
/boot →grub,kernel & initrd(initialise ram disk)contains files for system booting .
/bin→contains user binary and executable files and common commands
Files created by users stored in /bin , all rm mkdir commands implementation done
in bin .
/sbin →contains executable files unlike binaries it only contain system binaries which
require root privilege to perform certain task and for system maintenance file
(commands like fdisk, reboot, shutdown) used by administrators.
Performance Known for fast performance Known for reliability, security, and compatibility
and low overhead
Sharing Allows multiple users to Allows clients to share files with each other
share the same file
Printer sharing Doesn't provide printer Supports printer sharing
sharing
NTFS
100Mb →|4kb||4kb||4kb|→ stored
1024kbht tracker
A sandbox in Linux is a restricted environment that isolates processes or applications from the rest of
the system. This allows users to test programs without risking damage to the system.
Software development
Developers can use sandboxes to test new code, identify bugs, and validate changes.
A web application works by sending requests from a user's browser to a web server, which then
processes the request and sends back a response. The browser interprets the response and displays
the web application.
Steps
2. The web server receives the request and forwards it to the appropriate application.
3. The application generates a response in HTML, CSS, and JavaScript.
4. The web server sends the response back to the user's browser.
5. The browser interprets the response and displays the web application.
6. The user interacts with the web application, which may trigger client-side JavaScript.
Features
Web applications can include features like data processing, user authentication, and real-time
updates. They can be accessed from anywhere with an internet connection.
Considerations
Web applications can be affected by internet speed, app performance, and security.
Examples
Examples of web applications include social media platforms, online banking systems, and e-
commerce sites.
DLL→
Iss →
ISS and DLL are both file types that can be used in software. ISS may refer to ISS products that use
the iss-pam1.dll ICQ parser. DLL stands for Dynamic Link Library, a file that contains code and data
that can be used by multiple programs.
ISS
• A module that exploits a stack buffer overflow in the ISS products that use the iss-pam1.dll
ICQ parser has been identified.
DLL
• A DLL is a library that contains code and data that can be used by more than one program at
the same time.
• DLLs allow developers to write modular and efficient code and share resources among
different applications.
• DLLs can contain exported functions that are intended to be called by other modules.
• DLL hijacking attacks can be stealthy, difficult to detect, and can potentially result in serious
consequences.
• Multiple versions of the same DLL can exist in different file system locations within an
operating system.
DNS
HTTtracker,godaddy,catalyst
Continuous request more than 100 people at same time how it handled?
If you're talking specifically about webservers, then no, your formula doesn't work, because
webservers are designed to handle multiple, simultaneous requests, using forking or threading.
This turns the formula into something far harder to quantify - in my experience, web servers can
handle LOTS (i.e. hundreds or thousands) of concurrent requests which consume little or no time,
but tend to reduce that concurrency quite dramatically as the requests consume more time.
That means that "average service time" isn't massively useful - it can hide wide variations, and it's
actually the outliers that affect you the most.
Goals:
• Create high quality software as per client expectation,
• Satisfy client and bug free software
SDLC Phases:
Agile:
• Methodology used to create projects.
• Ability to move quickly
• Responding Swiftly to changa
Non Agile Methodology:
• The client can’t see the output of the project until the completion of the
project.
• Allocate extensive of time
Agile Methodology:
It have sprints or iterations which are shorter in duration during which pre-
determined features are developed.
Scrum:
Framework for managing work with an emphasis or software development
Software development→Iterations(with time-boxed)
Scrum Master
Daily
Product Owner
Sprint Roles Weekly
Development Team
Advantages:
• The Delivery of software is unremitting (Continuous).
• The Customers are satisfied because of after features are satisfied. If
customer have any feedback or changes it can do done releases.
• The daily changes are required for the business people and users.
Disadvantages:
• Documentations are reduced . For each iteration documentation is done
but for next iteration the previous documentation is not required as
many changes can be done.
• So complete project documentation is not done.
• Requirement may not be clear. It’s difficult to predict the expected
results.
• Starting stages of SDLC is predictable.
evO
DevOps is a set of practices, tools, and cultural philosophies that integrate software
development and IT operations. The goal of DevOps is to improve the speed, reliability, and
security of software.
• Build,Test,Deploy
• “Development Phase”
• But continuous change lead to manual
difficulties in operations.
• No pipieline
Jenkins is an open-source
automation tool that's • Build,Test,Deploy
• “Development & Operation
used to build, test, and
Phase ”
deploy software. It's also • Automation Pipeline
used to manage and (CI/CD)
automate the software
delivery process.
DevOps Practices
Continuous Integration
Continuous integration is a software development practice where developers regularly merge their
code changes into a central repository, after which automated builds and tests are run. The key
goals of continuous integration are to find and address bugs quicker, improve software quality, and
reduce the time it takes to validate and release new software updates.
Continuous Delivery
Continuous delivery is a software development practice where code changes are automatically built,
tested, and prepared for a release to production. It expands upon continuous integration by
deploying all code changes to a testing environment and/or a production environment after the build
stage. When continuous delivery is implemented properly, developers will always have a
deployment-ready build artifact that has passed through a standardized test process.
Microservices
The microservices architecture is a design approach to build a single application as a set of small
services. Each service runs in its own process and communicates with other services through a
well-defined interface using a lightweight mechanism, typically an HTTP-based application
programming interface (API). Microservices are built around business capabilities; each service is
scoped to a single purpose. You can use different frameworks or programming languages to write
microservices and deploy them independently, as a single service, or as a group of services.
Infrastructure as Code
Infrastructure as code is a practice in which infrastructure is provisioned and managed using code
and software development techniques, such as version control and continuous integration. The
cloud’s API-driven model enables developers and system administrators to interact with
infrastructure programmatically, and at scale, instead of needing to manually set up and configure
resources. Thus, engineers can interface with infrastructure using code-based tools and treat
infrastructure in a manner similar to how they treat application code. Because they are defined by
code, infrastructure and servers can quickly be deployed using standardized patterns, updated with
the latest patches and versions, or duplicated in repeatable ways.
Configuration Management
Developers and system administrators use code to automate operating system and host
configuration, operational tasks, and more. The use of code makes configuration changes
repeatable and standardized. It frees developers and systems administrators from manually
configuring operating systems, system applications, or server software.
Policy as Code
With infrastructure and its configuration codified with the cloud, organizations can monitor and
enforce compliance dynamically and at scale. Infrastructure that is described by code can thus be
tracked, validated, and reconfigured in an automated way. This makes it easier for organizations to
govern changes over resources and ensure that security measures are properly enforced in a
distributed manner (e.g. information security or compliance with PCI-DSS or HIPAA). This allows
teams within an organization to move at higher velocity since non-compliant resources can be
automatically flagged for further investigation or even automatically brought back into compliance.
DevOps Tools
The DevOps model relies on effective tooling to help teams rapidly and reliably deploy and innovate
for their customers. These tools automate manual tasks, help teams manage complex environments
at scale, and keep engineers in control of the high velocity that is enabled by DevOps. AWS provides
services that are designed for DevOps and that are built first for use with the AWS cloud. These
services help you use the DevOps practices described above.
DAY 5:
It provides a wide range of cloud base services including computing power, storage ,databases,
networking ,security and more.
It allows business and developers to build and manage applications without needing physical
hardware.
Key Features:
• On demand service- Pay only for what you use.
• Scalability -Easly scale up or down based on demand
• Security -Provides built in security features and compliance standard
• Global Availability- Aws operates multiple data centres world wide.
Compute:
Amazon ECS- Elastic container service manage service for running docker containers.
Storage:
S3 -Simple storage service- scalable object storage of files for backups and website.
Databases:
Redshift- fully managed cloud data warehouse that makes it simple and cost-effective to analyze all
your data.
RouteS3→DNS and store recent request and its info for fast acces
Cloudwatch→monitor resources
Cloudtrail→logs
DAY:6
Security
IAM (Identity and Access Management) is a framework used to manage users, roles, and permissions
within an organization or system. It ensures that the right individuals have the appropriate access to
resources while maintaining security and compliance.
It is responsible for securing the underlying infrastructure that supports the cloud.
Amazon S3 that stores files of different types like Photos, Audio, and Videos as Objects providing
more scalability and security to.
It allows the users to store and retrieve any amount of data at any point in time from anywhere on
the web.
Data Storage:
S3 Versioning
Github : https://github.com/ervishnucs/S3_Quiz
Traditional servers:
(Billed by seconds)
AMI’s are pre configured templates that include base OS and any additional software .
In a single package , It provides various combinations of CPU ,Memory , Storage and networking
capacity for provisioning instance .
• Type of instance
• How long do you run for?
• Right size your resources
• Choose the right IOPS of storage (Input output per second)
• Choose the right OS image
Creating Instances In EC2:
Serverless Computing
Automatic Scaling
Event Driven Execution: lambda function execute in response to triggers from AWS Services like S3
and API gateway
Stateless →Each execution is independent, so persistence storage must be handled using external
services like S3, Dynamo DB
Permissions Via IAM →Lambda use IAM roles to access other AWS Security.
Monitoring→ Integrated with AWS cloud watch for logging and performance tracking
Task :
When one image is added to the bucket it also to be added to bucket copy using AWS lambda
import json
import boto3
source_bucket = record['s3']['bucket']['name']
file_key = record['s3']['object']['key']
copy_source = {
'Bucket': source_bucket,
'Key': file_key
try:
except Exception as e:
return {
'statusCode': 200,
}
Aws Lambda
S3 Put
"Records": [
"eventVersion": "2.0",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "1970-01-01T00:00:00.000Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
},
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"responseElements": {
"x-amz-request-id": "EXAMPLE123456789",
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "testConfigRule",
"bucket": {
"name": "vqgbn",
"ownerIdentity": {
"principalId": "EXAMPLE"
},
"arn": "arn:aws:s3:::vqgbn"
},
"object": {
"key": "new.csv",
"size": 1024,
"eTag": "0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901"
Lambda Function
import boto3
s3_client = boto3.client("s3")
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("MarkSheet")
bucket_name = event['Records'][0]['s3']['bucket']['name']
s3_file_name = event['Records'][0]['s3']['object']['key']
resp = s3_client.get_object(Bucket=bucket_name,Key=s3_file_name)
data = resp['Body'].read().decode("utf-8")
Students = data.split("\n")
print(stud)
stud_data = stud.split(",")
# add to dynamodb
try:
table.put_item(
Item = {
"Roll_no" :int(stud_data[0]),
"Name" : stud_data[1],
"Mark" : stud_data[2]
except Exception as e:
print("End of file")
S3 Bucket:
DynamoDb:
Task2:
Create Lamda function to add items to CSV file from Table (DyanamoDB)
Lambda Functions:
import boto3
import csv
import os
dynamodb = boto3.resource("dynamodb")
s3_client = boto3.client("s3")
# DynamoDB table and S3 bucket details
table = dynamodb.Table(DYNAMODB_TABLE)
response = table.scan()
if not items:
return {
"statusCode": 404,
writer.writerow({
})
os.remove(CSV_FILE_NAME)
return {
"statusCode": 200,
Event :
"Records": [
"eventVersion": "2.0",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "1970-01-01T00:00:00.000Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
},
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"responseElements": {
"x-amz-request-id": "EXAMPLE123456789",
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "testConfigRule",
"bucket": {
"name": "qws34",
"ownerIdentity": {
"principalId": "EXAMPLE"
},
"arn": "arn:aws:s3:::qws34"
},
"object": {
"key": "new.csv",
"size": 1024,
"eTag": "0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901"
}
Task3:
Upload image meta data to Table when image is uploaded to the bucket
import boto3
import datetime
dynamodb = boto3.resource('dynamodb')
s3_event = event['Records'][0]['s3']
bucket_name = s3_event['bucket']['name']
object_key = s3_event['object']['key']
file_size = s3_event['object']['size']
# Current timestamp (upload time)
upload_time = datetime.datetime.utcnow().isoformat()
metadata_item = {
'filename': object_key,
'size': file_size,
'upload_date': upload_time
table.put_item(Item=metadata_item)
return {
'statusCode': 200,
Event :
"Records": [
"eventVersion": "2.0",
"eventSource": "aws:s3",
"awsRegion": "us-east-1",
"eventTime": "1970-01-01T00:00:00.000Z",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
},
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"responseElements": {
"x-amz-request-id": "EXAMPLE123456789",
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "testConfigRule",
"bucket": {
"ownerIdentity": {
"principalId": "EXAMPLE"
},
},
"object": {
"key": "krish.jpg",
"size": 1024,
"eTag": "0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901"
}
Day 8:
Launching Apache Server:
1⃣ Check Security Group Rules
• Go to EC2 Console > Instances > Select your instance > Security tab > Security Groups.
o (For IPv6, you can add ::/0 to allow all IPv6 traffic.)
Example:
bash
CopyEdit
bash
CopyEdit
sudo systemctl start httpd
bash
CopyEdit
css
CopyEdit
/var/www/html/
bash
CopyEdit
ls -l /var/www/html/
bash
CopyEdit
Make sure the /var/www/html directory and files have proper permissions:
bash
CopyEdit
• Your network administrator (or ISP) is blocking direct access to public IP addresses (like
http://3.91.123.45).
• This is common in corporate or educational networks, where direct access to IP-based URLs
is restricted (sometimes for security reasons, to block unregistered websites, or enforce
content filtering).
API
An API Gateway is a server that acts as an entry point of client request to access microservice or API
in the system .
It provides a single interface to manage and root request to appropriate services , offering various
benefits such as
• Request Routine – It Routes incoming request to the current backend service. Based on URL
paths ,headers or other factors.
• Authentication and Authorization : It can handle security concern by verifying manging users
amenities and permissions before passing request to backend services .
• Rate Limiting the gateway can limit the no if request from user or clients to prevent overload
on backend service.
• Load Balancing: Gateway can distribute request evenly across multiple instance . Of a service
to ensure optimal load handling .
• Monitoring & Logging : Provides centralized monitoring and logging for easier tracking for
traffic ,errors and performance.
API gateway is serverless and fully managed service and make it easy for developers to create,
publish, monitor , migrate and secure API
• RESTful API
• Web socket Application
Github : https://github.com/ervishnucs/SceneIt
Day 14 [8/3/25]:
DevOps
Platforn engr
Site Reliability Er
Devops vs Platform Er
IT Governance ,GDPR
Git pull → fetch & download content from a remote repo & immediate update to local repo
For each request we should write what are they obtained? Tools used ? what are achieved? What is
done with the file?
Environment:
Devlopement
Testing
Pre Product Demo – Some un handled edge cases may not be handled .Some team are allocated to
this env .Minor edge case can be identified.
Buid ===
Pipeline===
Jenkins , Gitlab
CI/CD Deploy==
{ Microservice Architect.--> Integ. Of diff app → Deploy } Build ,test ,deploy ,run
Release==
Monitoring in metrics
Logging and monitoring
Security===
What is Virtualization?
Virtualization is a technology that creates virtual versions of computer resources such as hardware
platforms, operating systems, storage devices, and network resources. It’s like creating a software-
based replica of a physical machine, allowing you to run multiple isolated environments on the same
hardware or across a distributed system.
• Imagine you have a powerful computer but you only use a small portion of its resources.
• Virtualization allows you to split that computer into several virtual machines (VMs), each
acting like a separate computer with its operating system and applications.
• Each virtual machine is isolated from the others, meaning issues in one virtual machine
won’t affect others.
• This allows you to optimize resource utilization, run multiple applications on a single
machine, and improve scalability by easily adding or removing virtual machines as needed.
What is Containerization?
Containerization is a lightweight form of virtualization that allows you to run applications and their
dependencies in isolated containers. Each container shares the same operating system kernel but is
isolated from other containers, providing a portable and consistent runtime environment for
applications.
• Containers provide process isolation, ensuring that applications running in one container do
not affect applications running in other containers.
• Containers are lightweight compared to traditional virtual machines (VMs) because they
share the host operating system kernel.
• Containers are designed to be scalable, allowing you to quickly scale up or down based on
demand.
• Containers enable developers to build, test, and deploy applications more efficiently, leading
to faster release cycles and improved collaboration between development and operations
teams.
Virtualization Vs. Containerization
Each VM runs its own guest Containers share the host operating
Isolation operating system system kernel
Each VM requires its own set of Containers are lightweight and share
Resource Usage resources host resources
May have higher overhead due to Lower overhead as containers share the
Performance multiple OS instances host OS kernel
VMs are less portable due to Containers are highly portable across
Portability varying guest OS different systems
Resource Requires more resources as each More efficient resource utilization with
Utilization VM has its own OS containerization
The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as
images, containers, networks, and volumes.
The Docker client (docker) is the primary way that many Docker users interact with Docker. When
you use commands such as docker run, the client sends these commands to dockerd, which carries
them out.
Docker registries
A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and
Docker looks for images on Docker Hub by default. You can even run your own private registry.
When you use the docker pull or docker run commands, Docker pulls the required images from your
configured registry. When you use the docker push command, Docker pushes your image to your
configured registry.
Images
An image is a read-only template with instructions for creating a Docker container. Often, an image is
based on another image, with some additional customization.
Docker Desktop for Windows, WSL (Windows Subsystem for Linux) 2 is a backend that allows you to
run Linux containers on Windows, leveraging a full Linux kernel and improving file system sharing
and boot times, according to Docker Docs.
WSL is a feature in Windows that allows you to run a Linux environment (including command-line
tools and GUI apps) directly on Windows, without needing a virtual machine or dual boot.
Docker Desktop for Windows uses WSL 2 as a backend to run the Docker daemon and containers,
enabling you to run both Linux and Windows containers on the same machine.
This command is used to run a container from an image. The docker run command is a combination
of the docker create and docker start commands. It creates a new container from the image specified
and starts that container. if the docker image is not present, then the docker run pulls that.
Docker Pull
This command allows you to pull any image which is present in the official registry of docker, Docker
hub. By default, it pulls the latest image, but you can also mention the version of the image.
This command (by default) shows us a list of all the running containers. We can use various flags with
it.
$ docker ps [options..]
Docker Stop
This command allows you to stop a container if it has crashed or you want to switch to another one.
Docker Start
Suppose you want to start the stopped container again, you can do it with the help of this command.
Docker rm
Docker RMI
To delete the image in docker. You can delete the images which are useless from the docker local
storage so you can free up the space
Docker Images
Lists all the pulled images which are present in our system.
$ docker images
Docker exec
This command allows us to run new commands in a running container. This command only works
until the container is running, after the container restarts, this command does not restart.
In order to access the docker container from the outside world, we have to map the port on our
host( Our laptop for example), to the port on the container. This is where port mapping comes into
play.
So these were the 9 most basic docker commands that every beginner must know. Containerization
is a very vast topic but you can start from the very basic commands and by practicing them daily you
can master them.
Docker Login
The Docker login command will help you to authenticate with the Docker hub by which you can push
and pull your images.
docker login
It will ask you to enter the username and password after that you will authenticate with DockerHub
and you can perform the tasks.
Docker Push
Once you build your own customized image by using Dockerfile you need to store the image in the
remote registry which is DockerHub for that you need to push your image by using the following
command. To know more about How to Push a Container Image to a Docker Repository?
Docker Build
The docker build command is used to build the docker images with the help of Dockerfile.
Docker Stop
You can stop and start the docker containers where you can do the maintenance for containers. To
stop and start specific containers you can use the following commands.
Instead of stopping a single container. You can stop multiple containers at a time by using the
following commands.
Docker Restart
While running the containers in Docker you may face some errors and containers fails to start. You
can restart the containers to resolve the containers by using the following commands.
Docker Inspection
Docker containers will run into some errors in real time to debug the container’s errors you can use
the following commands.
After running the containers by using the current image you can make the updates to the containers
by interacting with the containers from that containers you can create an image by using the
following commands.
1. docker images: Docker images will list all the images which are pulled or build in that docker
host.
2. docker pull: Docker pull will the docker images from the dockerhub.
3. docker run: Docker run will run the docker image as an container.
4. docker ps: Docker run will list all the containers which are running in the docker host.
5. docker stop: Docker stop will stop the docker container which are already running.
6. docker rm: Docker rm command will remove the containers which are in the stop condition.
1. docker build command: It will build Docker images by using the Dockerfile.
2. docker pull command: Docker pull command will pull the Docker image whcih is avalible in
the dockerhub.
3. docker images command: It will list all the images which are pulled and build in the docker
host.
4. docker inspect command: It will helps to debug the docker image if any errors occurred
while building an image or pulling the image.
5. docker push command: Docker command will push the docker image into the Dockerhub.
6. docker save command: It will save the docker image in the form of dockerfile.
Docker File:
The following are the stages of creating docker image form Dockerfile:
Dockerfile commands/Instructions
1. FROM
• Represents the base image(OS), which is the command that is executed first before any other
commands.
Syntax
FROM <ImageName>
FROM ubuntu:19.04
2. COPY
• The copy command is used to copy the file/folders to the image while building the image.
Syntax:
3. ADD
• While creating the image, we can download files from distant HTTP/HTTPS destinations using
the ADD command.
Syntax
ADD <URL>
ADD https://get.jenkins.io/war/2.397/jenkins.war
4. RUN
• Scripts and commands are run with the RUN instruction. The execution of RUN commands or
instructions will take place while you create an image on top of the prior layers (Image).
Syntax
Example
5. CMD
• The main purpose of the CMD command is to start the process inside the container and it
can be overridden.
Syntax
6. ENTRYPOINT
• A container that will function as an executable is configured by ENTRYPOINT. When you start
the Docker container, a command or script called ENTRYPOINT is executed.
• It can’t be overridden.The only difference between CMD and ENTRYPOINT is CMD can be
overridden and ENTRYPOINT can’t.
Syntax
7. MAINTAINER
• By using the MAINTAINER command we can identify the author/owner of the Dockerfile and
we can set our own author/owner for the image.
Syntax:
MAINTAINER <NAME>
Docker Networking
Networking allows containers to communicate with each other and with the host system. Containers
run isolated from the host system and need a way to communicate with each other and with the
host system.
By default, Docker provides two network drivers for you, the bridge and the overlay drivers.
docker network ls
Bridge Networking
The default network mode in Docker. It creates a private network between the host and containers,
allowing containers to communicate with each other and with the host system.
If you want to secure your containers and isolate them from the default bridge network you can also
create your own bridge network.
Now, if you list the docker networks, you will see a new network.
docker network ls
This new network can be attached to the containers, when you run these containers.
This way, you can run multiple containers on a single host platform where one container is attached
to the default network and the other is attached to the my_bridge network.
These containers are completely isolated with their private networks and cannot talk to each other.
However, you can at any point of time, attach the first container to my_bridge network and enable
communication
This mode allows containers to share the host system's network stack, providing direct access to the
host system's network.
To attach a host network to a Docker container, you can use the --network="host" option when
running a docker run command. When you use this option, the container has access to the host's
network stack, and shares the host's network namespace. This means that the container will use the
same IP address and network configuration as the host.
Here's an example of how to run a Docker container with the host network:
Keep in mind that when you use the host network, the container is less isolated from the host
system, and has access to all of the host's network resources. This can be a security risk, so use the
host network with caution.
Additionally, not all Docker image and command combinations are compatible with the host
network, so it's important to check the image documentation or run the image with the --
network="bridge" option (the default network mode) first to see if there are any compatibility issues.
Overlay Networking
This mode enables communication between containers across multiple Docker host machines,
allowing containers to be connected to a single network even when they are running on different
hosts.
Macvlan Networking
This mode allows a container to appear on the network as a physical host rather than as a container.
Docker Volumes
## Problem Statement
It is a very common requirement to persist the data in a Docker container beyond the lifetime of the
container. However, the file system
## Solution
1. Volumes
### Volumes
Volumes aims to solve the same problem by providing a way to store data on the host file system,
separate from the container's file system,
so that the data can persist even if the container is deleted and recreated.

Volumes can be created and managed using the docker volume command. You can create a new
volume using the following command:
```
```
Once a volume is created, you can mount it to a container using the -v or --mount option when
running a docker run command.
For example:
```
```
This command will mount the volume <volume_name> to the /data directory in the container. Any
data written to the /data directory
inside the container will be persisted in the volume on the host file system.
Bind mounts also aims to solve the same problem but in a complete different way.
Using this way, user can mount a directory from the host file system into a container. Bind mounts
have the same behavior as volumes, but
For example,
```
```
Volumes are managed, created, mounted and deleted using the Docker API. However, Volumes are
more flexible than bind mounts, as
they can be managed and backed up separately from the host file system, and can be moved
between containers and hosts.
In a nutshell, Bind Directory on a host as a Mount are appropriate for simple use cases where you
need to mount a directory from the host file system into
a container, while volumes are better suited for more complex use cases where you need more
control over the data being persisted
in the container.
Day 15:
Artifactory is a branded term to refer to a repository manager that organizes all of your binary
resources. These resources can include remote artifacts, proprietary libraries, and other third-party
resources. A repository manager pulls all of these resources into a single location.
Incident response (IR) refers to an organization's processes and technologies for detecting,
containing, and recovering from cybersecurity incidents, breaches, or cyberattack
Root cause analysis (RCA) is defined as a collective term that describes a wide range of approaches,
tools, and techniques used to uncover causes of problems.
Stage:Build
BuildImage
Docker Build
Stage :Push
Stage:Deploy
DeploytoEC2
Docker run
.sh
Tools in Devops
1)Repo
1)ARGO CD
Need of Kubernetes
What is Kubernetes?
YAML:
---
pi: 3.14159
xmas: true
french-hens: 3
calling-birds:
- huey
- dewey
- louie
- fred
xmas-fifth-day:
calling-birds: four
french-hens: 3
golden-rings: 5
partridges:
count: 1
JSON
"pi": 3.14159,
"xmas": true,
"french-hens": 3,
"calling-birds": [
"huey",
"dewey",
"louie",
"fred"
],
"xmas-fifth-day": {
"calling-birds": "four",
"french-hens": 3,
"golden-rings": 5,
"partridges": {
"count": 1,
},
"turtle-doves": "two"
Arrays :
---
items:
-1
-2
-3
-4
-5
names:
- "one"
- "two"
- "three"
- "four"
String :
---
---
nested :
---
foo:
bar:
- bar
- rab
- plop
Kubernetes:
Nodes →VM
Kube-proxy is the routing layer used by Kubernetes to route traffic between nodes in a cluster. Built
on iptables, kube-proxy operates at Layer 4, e.g., it routes TCP, UDP, and SCTP.
CoreDNS is a flexible, extensible DNS server that can serve as the Kubernetes cluster DNS. When you
launch an Amazon EKS cluster with at least one node, two replicas of the CoreDNS image are
deployed by default, regardless of the number of nodes deployed in your cluster.
the primary node agent that runs on each node and is responsible for managing and maintaining
containers, ensuring they match the desired state specified in pod definitions
Day 16:
Kubernetes – Architecture
Kubernetes comes with a client-server architecture. It consists of master and worker nodes, with the
master being installed on a single Linux system and the nodes on many Linux workstations.
The master node, contains the components such as API Server, controller manager, scheduler, and
etcd database for stage storage. kubelet to communicate with the master, the kube-proxy for
networking, and a container runtime such as Docker to manage containers.
Kubernetes Components
Kubernetes is composed of a number of components, each of which plays a specific role in the
overall system. These components can be divided into two categories:
• nodes: Each Kubernetes cluster requires at least one worker node, which is a collection of
worker machines that make up the nodes where our container will be deployed.
• Control plane: The worker nodes and any pods contained within them will be under the
control plane.
Control Plane Components
It is basically a collection of various components that help us in managing the overall health of a
cluster. For example, if you want to set up new pods, destroy pods, scale pods, etc. Basically, 4
services run on Control Plane:
1. Kube-API server
The API server is a component of the Kubernetes control plane that exposes the Kubernetes API. It is
like an initial gateway to the cluster that listens to updates or queries via CLI like Kubectl. Kubectl
communicates with API Server to inform what needs to be done like creating pods or deleting pods
etc. It also works as a gatekeeper. It generally validates requests received and then forwards them to
other processes. No request can be directly passed to the cluster, it has to be passed through the API
Server.
2. Kube-Scheduler
When API Server receives a request for Scheduling Pods then the request is passed on to the
Scheduler. It intelligently decides on which node to schedule the pod for better efficiency of the
cluster.
3. Kube-Controller-Manager
The kube-controller-manager is responsible for running the controllers that handle the various
aspects of the cluster’s control loop. These controllers include the replication controller, which
ensures that the desired number of replicas of a given application is running, and the node
controller, which ensures that nodes are correctly marked as “ready” or “not ready” based on their
current state.
4. etcd
It is a key-value store of a Cluster. The Cluster State Changes get stored in the etcd. It acts as the
Cluster brain because it tells the Scheduler and other processes about which resources are available
and about cluster state changes.
1. Container runtime
A container runtime is needed to run the application containers running on pods inside a pod.
Example-> Docker
2. kubelet
kubelet interacts with both the container runtime as well as the Node. It is the process responsible
for starting a pod with a container inside.
3. kube-proxy
It is the process responsible for forwarding the request from Services to the pods. It has intelligent
logic to forward the request to the right pod in the worker node.
Indivisibe unit
To view a list of all the pods in the cluster, you can use the following command:
To view a list of all the services in the cluster, you can use the following command:
Minikube is a one node Kubernetes cluster that runs in VirtualBox on your local machine in order to
test Kubernetes on your local set up. In order to setup a production cluster, we need multiple master
notes and multiple worker nodes. Master nodes and worker nodes have their own separate
responsibilities. In order to test something on our local environment for example - deploying a new
application or a new component and to test it on our local machine, it will be very difficult and would
consume a lot of resources like CPU, memory etc.
Minikube comes into play here. Minikube is an open-source tool that is basically like a one node
cluster where the master processes and the work processes both run on one node. This node must
have a Docker container runtime pre-installed to run the containers or pods with containers on this
node.
Kubectl is the Kubernetes CLI tool. To know more about Kubectl, read the following article on
GeeksforGeeks - Kubernetes - Kubectl. Follow these steps to deploy a service using Minikube and
Kubectl:
minikube start
If you are logged in as a root user you might get an error message:
Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
This is because the default driver in the Docker driver and it should not be used with root privileges.
For fixing this we should log in as a different user that the root user.
Enter the following command to add a new user
adduser [USERNAME]
su - [USERNAME]
minikube start
you will get a similar output, wait for some time until the installation of dependencies gets
completed:
Step 2. Now if we check the number of nodes running, we will get the minikube node running.
or you can also check the status by running the following command:
minikube status
Step 2. To find out the services that are currently running on Kubernetes enter the following
command:
Step 4. Enter the following command to expose the deployment to the port 6000:
Step 6. Now to run the service, enter the following minikube command:
You have to just copy the address (http://127.0.0.1:42093/ for me) and paste it to your browser to
see the application website. It looks like the following:
You just have to simply enter the following command to delete the minikube cluster.
minikube delete
minikube pause
minikube unpause
minikube stop
C:\Users\pmlba>minikube start
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
C:\Users\pmlba>minikube status
minikube
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
deployment.apps/vishnu created
X Exiting due to SVC_NOT_FOUND: Service 'vishnu' was not found in 'default' namespace.
You may select another namespace by using 'minikube service vishnu -n <namespace>'. Or list out all
the services using 'minikube service list'
service/vishnu exposed
|-----------|--------|-------------|---------------------------|
|-----------|--------|-------------|---------------------------|
|-----------|--------|-------------|---------------------------|
|-----------|--------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|--------|-------------|------------------------|
|-----------|--------|-------------|------------------------|
! Because you are using a Docker driver on windows, the terminal needs to be open to run it.
apiversions:apps/v1
kind:deployment
metadata:
name:nginx-deployment
selector:
matchlabels:
app:nginx
templates:
metadata:
labels:
app:nginx
spec:
containers:
-name:nginx
Image:nginx-latest
Port:
-containerPort:80
Even you create the duplicate pods the Kubernetes will have unique name for each pods
Round Robin Algo→Schedule pods in nodes across diff zones in diff nodes
However , we use only single URL to work in this only one endpoint for n no of pods
apiversions:apps/v1
kind:service ------------→this makes the diff in automation ,this help you manage states even pods
deleted
metadata:
name:nginx-deployment
selector:
matchlabels:
app:nginx
templates:
metadata:
labels:
app:nginx
spec:
containers:
-name:nginx
Image:nginx-latest
Port:
-containerPort:80
Day :17 & 18
Task 1: Create next.js file in EC2 server and deploy using Jenkins
node -v
npm -v
cd your-repo
npm install
pm2 save
pm2 startup
sudo vi /etc/nginx/sites-available/default
# Add this config:
server {
listen 80;
server_name YOUR_SERVER_IP;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
# Restart Nginx
# Check Logs
sudo su - jenkins
sudo vi /etc/sudoers
1. Login to Jenkins
o https://github.com/your-username/your-nextjs-repo.git
o npm install
o pm2 save
o Click Add Post-Build Action → Git Publisher (optional for tagging builds)
4. pipeline {
5. agent any
6.
7. stages {
8. stage('Checkout Code') {
9. steps {
11. }
12. }
13.
15. steps {
17. }
18. }
19.
21. steps {
23. }
24. }
25.
27. steps {
28. sh '''
29. pm2 restart nextjs-app || pm2 start npm --name "nextjs-app" -- start
31. '''
32. }
33. }
34. }
35.
36. post {
37. success {
39. }
40. failure {
42. }
43. }
44. }
7. Save Webhook
Steps to Deploy "Hello World" in EC2 and Integrate with Jenkins & GitHub (CI/CD Pipeline)
o Write a simple "Hello, World!" Python script and store it in a GitHub repository.
o Set up a Jenkins Pipeline Job to pull the latest code from GitHub and deploy it.
Step-by-Step Implementation
6. Install Jenkins:
9. https://pkg.jenkins.io/redhat/jenkins.repo
3. cd your-repo
5. pipeline {
6. agent any
7. stages {
8. stage('Checkout') {
9. steps {
11. }
12. }
16. }
17. }
19. steps {
20. script {
22. if (changes) {
23. sh '''
29. '''
30. }
31. }
32. }
33. }
34. }
35. }
3. http://<EC2-PUBLIC-IP>:8080/github-webhook/
provider "aws" {
region = "us-east-1"
instance_type = "t2.micro"
key_name = aws_key_pair.my_key.key_name
security_groups = [aws_security_group.ec2_sg.name]
tags = {
Name = "Terraform-EC2-With-SG"
Task2:Creating S3 Bukets
provider "aws" {
region = "us-east-1"
bucket = "my-terraform-bucket-${random_id.bucket_id.hex}"
tags = {
Name = "MyTerraformS3Bucket"
}
resource "random_id" "bucket_id" {
byte_length = 4
Task3:Creating EC2 instance along with a .pem file and attach to the instance
provider "aws" {
region = "us-east-1"
algorithm = "RSA"
rsa_bits = 2048
content = tls_private_key.my_ssh_key.private_key_pem
filename = "${path.module}/my-terraform-key.pem"
file_permission = "0600"
key_name = "my-terraform-key"
public_key = tls_private_key.my_ssh_key.public_key_openssh
instance_type = "t2.micro"
tags = {
Name = "Terraform-EC2-With-Generated-Key"
Terraform init
Terraform validate
Terraform plan
Terraform apply
provider "aws" {
region = "us-east-1"
name = "ec2-security-group"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
egress {
from_port = 0
to_port =0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
name = "ec2-security-group"
CopyEdit
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
Allows HTTP traffic (port 80) from anywhere (useful for web servers). If you need HTTPS (secure
traffic), add port 443:
egress {
from_port = 0
to_port =0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
Day 20