Devops Notes
What is DevOps?
DevOps = Development + Operations
- Bridge the gap between developers (who write code) and operations (who deploy and maintain apps).
Common DevOps Tools:
| Category | Tools |
|---|---|
| Source control | Git, GitHub, GitLab |
| CI/CD (automation) | Jenkins, GitHub Actions, CircleCI |
| Configuration management | Ansible, Puppet, Chef |
| Containerization | Docker |
| Orchestration | Kubernetes |
| Monitoring | Prometheus, Grafana |
DevOps is about how you build, deploy, and manage applications efficiently.
Git :
rohith@rohith-ROG-Strix-G513RC-G513RC:~$ git --version
git version 2.43.0
rohith@rohith-ROG-Strix-G513RC-G513RC:~$ git config --global user.name "rohith" (To assign your name)
rohith@rohith-ROG-Strix-G513RC-G513RC:~$ git config --global user.email "rohithvishva2005@gmail.com" (Email)
Git Branch — a parallel version of the main code
Commands :
Initialize project
git init
git add .
git commit -m "Initial commit"
Create remote and push
git branch -M main
git remote add origin https://github.com/username/repo.git
git push -u origin main
Create new feature branch
git checkout -b feature/login
Work on feature
git add .
git commit -m "Add login feature"
Merge back to main
git checkout main
git pull
git merge feature/login
git push
Github actions :
the above image explains a code in local pc is sent to github and server is pulling it , and composed in a docked file now , when we change any code in local pc , we need to follow these steps manually , so we use CI/CD pipelines to avoid this manual steps
CI/CD - giving a script which can repeat in every push
these script is given in .yaml file which include
- whenever there is a push
- SSH into my server
- CD / home / app
- git pull
- docker compose file up -d
and we write docker file — Dockerfile
and in docker-compose.yml
and after this u need to have a server to access and get SSH code ref (YT)- https://youtu.be/y7S2oSjJ8PA?si=SKbKBvwkB5k9rwBN
now we are doing github actions : automation of pull to server and build docker image
in root create folder named .github inside that crerate folder named workflow and in that a file named deploy.yaml
deploy.yaml
Linux :
1. Introduction to Linux in DevOps
Why Linux is important
Linux is the backbone of modern DevOps because:
- Most DevOps tools are built for Linux:
- Docker
- Kubernetes
- Git
- Jenkins
- Terraform
- Cloud servers (AWS, Azure, GCP) primarily run Linux
- High stability and uptime
- Better security model (permissions & isolation)
- Excellent performance and resource efficiency
- Open source and highly customizable
Accessing Linux on Windows using WSL (Windows Subsystem for Linux)
Install Ubuntu on Windows:
wsl --install
Check installed distributions:
wsl --list --verbose
Start Linux shell:
wsl
Now you can use Linux terminal directly on Windows.
2. Navigating the Linux File System
Basic navigation commands
| Command | Purpose |
|---|---|
pwd | Show current directory |
ls | List files |
ls -l | Detailed file list |
ls -a | Include hidden files |
cd folder | Move into folder |
cd .. | Go back one level |
cd ~ | Go to home directory |
cd / | Go to root directory |
File & directory management
| Command | Purpose |
|---|---|
touch file.txt | Create empty file |
mkdir folder | Create folder |
rm file.txt | Delete file |
rm -r folder | Delete folder recursively |
cp file1 file2 | Copy file |
mv file newLocation/ | Move / rename file |
Examples:
touch app.js
mkdir server
mv app.js server/
rm app.js
3. Searching Files
Using find
Search for a file by name:
find ~/Desktop -name "file1.txt"
Using grep
Search inside files for text:
grep "hello" file1.txt
Recursive search:
grep -r "password" .
4. Shell Scripting Basics
What is shell scripting?
- A shell script is a file containing Linux commands
- Used to automate tasks
- Runs sequentially
- Saves time and avoids human errors
Basic script structure
#!/bin/bash
echo "Hello World"
#!/bin/bash → tells system to use Bash shell
Creating & running a script
nano script.sh
chmod +x script.sh
./script.sh
Explanation:
nano script.sh→ create file
chmod +x→ make executable
./script.sh→ run script
5. Variables & Conditions
Variables
#!/bin/bash
name="Alice"
echo "Hello $name"
Rules:
- No spaces around
=
- Access using
$variable
If condition example
#!/bin/bash
num=5
if [ $num -gt 3 ]; then
echo "Number > 3"
else
echo "Number <= 3"
fi
Comparison operators:
| Operator | Meaning |
|---|---|
-gt | greater than |
-lt | less than |
-eq | equal |
-ne | not equal |
6. Applying Shell Scripts in MERN Projects
Use case: Start backend and frontend together
Instead of opening two terminals, automate using a script.
Create file:
start.sh
Script content:
#!/bin/bash
echo "Starting MERN application..."
# Start backend
cd server || exit
npm start &
# Start frontend
cd ../client || exit
npm run dev
Make executable:
chmod +x start.sh
Run:
./start.sh
Docker :
1. Traditional Problem
Normally, apps run differently on different machines because of:
- Different OS versions
- Missing dependencies
- Configuration conflicts
For example, something that works on your laptop might fail on a server.
2. What Docker Does
Docker packages your app + all its dependencies (like libraries, configs, OS tools) into a container.
This container can run anywhere, no matter the environment.
3. Key Concepts
| Term | Description |
|---|---|
| Image | A blueprint for your container (like a snapshot of your app + environment). Docker Images are - Lightweight , - Standalone , Executable Package |
| Container | A running instance of an image. Each container is isolated but lightweight. Downloading packages running commands happens here |
| Docker file | A script that defines how to build an image (commands like FROM, RUN, COPY). |
| Docker Hub | A cloud registry to store and share images (like GitHub for Docker). |
| Docker Engine | The core service that builds and runs containers. |
| Docker Volume | A Docker volume is a permanent storage mechanism that lets data survive even after a container is deleted or recreated. |
| Docker Network | A Docker network connects containers together — allowing them to communicate securely and easily. By default, containers are isolated — they can’t talk to each other or the outside world unless connected to a network. |
-imp
-normal
1.Basic Docker Commands
| Command | Description |
|---|---|
docker --version | Check Docker version |
docker info | Show system-wide information |
docker help | List all Docker commands |
docker <command> --help | Help for a specific command |
2.Docker Images
| Command | Description |
|---|---|
docker images | List all images |
docker pull <image> | Download an image from Docker Hub |
docker search <name> | Search images on Docker Hub |
docker rmi <image> | Remove an image |
docker rmi $(docker images -q) | Remove all images |
docker inspect <image> | View detailed info about an image |
docker history <image> | Show image build history |
docker tag <source> <target> | Tag an image |
docker save -o <file.tar> <image> | Save image to a tar file |
docker load -i <file.tar> | Load image from a tar file |
docker run -d <image_name> | detach mode, detaches and run behind the terminal |
3.Docker Containers
| Command | Description |
|---|---|
docker ps | List running containers |
docker ps -a | List all containers (including stopped) |
docker run <image> | Run a container |
docker run -it <image> bash | Run container in interactive terminal |
docker start <containerID> | Start a stopped container by id u can access a particular container |
docker stop <container> | Stop a running container |
docker restart <container> | Restart a container |
docker rm <container> | Remove a stopped container |
docker rm -f <container> | Force remove running container |
docker logs <container> | View container logs |
docker exec -it <container> bash | Open terminal inside a container |
docker inspect <container> | Get detailed info about container |
docker top <container> | Show processes running inside a container |
docker stats | Show container resource usage |
docker rename <old> <new> | Rename a container |
docker exec -it <container_id> /bin/bash |
4.Docker Volumes (Data Storage)
| Command | Description |
|---|---|
docker volume create <name> | Create a volume |
docker volume ls | List all volumes |
docker volume inspect <name> | Show volume details |
docker volume rm <name> | Remove a volume |
docker volume prune | Remove all unused volumes |
docker run -v <volume>:/path/in/container <image> | Attach volume to container |
5.Docker Networks
| Command | Description |
|---|---|
docker network ls | List networks |
docker network create <name> | Create a network |
docker network inspect <name> | Inspect a network |
docker network connect <network> <container> | Connect container to network |
docker network disconnect <network> <container> | Disconnect container |
docker network rm <name> | Remove a network |
docker network prune | Remove all unused networks |
6.Docker Compose
| Command | Description |
|---|---|
docker compose up | Start services defined in docker-compose.yml |
docker compose up -d | Start services in background |
docker compose down | Stop and remove containers, networks, volumes |
docker compose ps | List running services |
docker compose logs | View service logs |
docker compose restart | Restart services |
docker compose exec <service> bash | Run a command in a service container |
7.Docker System Maintenance
| Command | Description |
|---|---|
docker system df | Show disk usage |
docker system prune | Remove all unused data (containers, networks, etc.) |
docker system prune -a | Remove all unused images and containers |
docker builder prune | Remove unused build cache |
8.Docker Build
| Command | Description |
|---|---|
docker build -t <name> . | Build image from Dockerfile |
docker build -f <Dockerfile> -t <name> . | Specify a custom Dockerfile |
docker commit <container> <image> | Create image from container changes |
docker history <image> | View image layer history |
9.Docker Login / Registry
| Command | Description |
|---|---|
docker login | Log in to Docker Hub |
docker logout | Log out from Docker Hub |
docker push <image> | Push image to Docker Hub |
docker pull <image> | Pull image from Docker Hub |
10.Docker Permissions (Non-root setup)
To run Docker without sudo:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Then verify:
docker ps
Bonus: Useful One-Liners
| Command | Description |
|---|---|
docker stop $(docker ps -q) | Stop all containers |
docker rm $(docker ps -aq) | Remove all containers |
docker rmi $(docker images -q) | Remove all images |
docker volume rm $(docker volume ls -q) | Remove all volumes |
docker network rm $(docker network ls -q) | Remove all networks |
// IMP
docker run <image>
docker run -d <image> {runs behind , will not load in terminal}
docker run —name my-container <image>
docker run -v $(pwd):<image> {pwd - present working directory }
docker run -it <image> sh {to intract with container
docker ps
docker ps -a
docker logs <container>
docker attach <container>
docker stop <container>
docker kill <container>
docker stop $(docker ps -a)
docker start <container>
docker rm <cont>
docker cp <cont> :/path/
| Symbol | Meaning | Example | Description |
|---|
. | current directory | ./file.js | Refers to the file or folder in the same folder as the current file. |
.. | parent directory | ../config.js | Goes one level up from the current folder. |
../.. | two levels up | ../../env/.env | Goes two levels up the directory tree. |
/ | root (depends on context) | /home/user/project | In absolute paths — refers to the root directory. |
./ | same as . but used for clarity | ./index.js | Explicitly tells code “this file is in the current directory.” |
CI: → Continuous Integration
It’s the DevOps practice of automatically building, testing, and integrating code changes whenever developers push updates to a shared repository (like GitHub, GitLab, or Bitbucket).
common problems : you dont find bugs until days or weeks
merge conflict can pile up
one change can break multiple other changes
tier :
P0 > P1 > P2 > P3 > P4
P0 → main code , p4 , p3 test codes
// 1 → main branch → devbranch (copy of main) → all other developers branch (Dev1 , Dev2 , Dev3) {they push to dev and if everything is good update main}
Developer → Pushes code → GitHub triggers CI pipeline →
CI server builds + runs tests → Reports success or failure
CI vs CD — Full Explanation
CI/CD is a DevOps practice that automates integration, testing, delivery, and deployment of software.
It has 3 major stages:
- CI – Continuous Integration
- CD – Continuous Delivery
- CD – Continuous Deployment
(yes, the “CD” has two meanings)
1. Continuous Integration (CI)
Definition
CI is the practice of automatically building and testing code every time a developer pushes changes.
Goal
Catch bugs early → prevent broken code from entering the main branch.
What CI includes
- Installing dependencies
- Running tests (unit/integration)
- Running ESLint checks
- Running Prettier checks
- Running type checks (TypeScript)
- Building the project
- Verifying code quality
CI Tools
- GitHub Actions
- GitLab CI
- Jenkins
- CircleCI
- TravisCI
- Azure DevOps
Main Use Cases
- Ensure code compiles successfully
- Detect bugs automatically
- Prevent bad code from being merged
- Enforce coding standards (lint)
- Run automated tests before merging
- Speed up team collaboration
2. Continuous Delivery (CD)
Definition
Continuous Delivery takes the output of CI and prepares it for deployment, but requires manual approval before production.
Goal
Keep the app always ready to deploy with one click.
What Continuous Delivery includes
- Packaging the application
- Creating Docker images
- Uploading artifacts (zip, jars, dist folder)
- Pushing Docker images to registry (Docker Hub, AWS ECR)
- Running staging environment builds
- Deployment manual trigger required
CD Tools
- GitHub Actions
- GitLab CD
- Jenkins (Pipeline)
- ArgoCD
- Spinnaker
Main Use Cases
- Deploy to staging environment
- Allow QA to test before release
- Ensure release builds are always ready
- Human-approved deployment to production
3. Continuous Deployment (CD)
Definition
Continuous Deployment automatically deploys code to production after all tests/validations pass.
No manual approval. Fully automatic.
Goal
Fastest delivery of new features → automation end-to-end.
What Continuous Deployment includes
- Auto deploy to production servers
- Auto push Docker containers to Kubernetes
- Auto scaling & rolling updates
- Monitoring after deployment
Tools for Continuous Deployment
- Kubernetes
- ArgoCD
- Spinnaker
- GitHub Actions (can be used)
- Amazon CodePipeline
Main Use Cases
- High-frequency deployments
- SaaS platforms (e.g., Netflix, Facebook)
- Fully automated DevOps pipelines
- Teams that deploy multiple times per day
Summary Table — CI vs CD vs CD
| Feature / Aspect | CI (Integration) | CD (Delivery) | CD (Deployment) |
|---|---|---|---|
| Runs on push | ✔ | ✔ | ✔ |
| Automated testing | ✔ | ✔ | ✔ |
| Automated builds | ✔ | ✔ | ✔ |
| Creates deployable artifacts | ✖ | ✔ | ✔ |
| Requires manual approval | ✖ | ✔ | ✖ |
| Auto-deploy to production | ✖ | ✖ | ✔ |
| Uses Docker | Optional | ✔ | ✔ |
| Uses Kubernetes | ✖ | Optional | ✔ |
| Main goal | Code quality | Ready-to-deploy releases | Auto deploy to production |
| Difficulty level | Easy | Medium | Hard |
Where does Docker fit?
Docker is mainly used in:
Continuous Delivery → Packaging
- Build Docker image
- Push to registry
Continuous Deployment → Deployment
- Deploy Docker image to server/Kubernetes
Docker is NOT CI-only.
But CI can also build Docker images for testing.
Practical Example in a MERN Project
● CI Tasks
npm install
npm run lint
npm test
npm run build
- Verify backend routes
● Continuous Delivery Tasks
docker build
docker push
- Prepare release artifacts
- Deploy to staging serverT
● Continuous Deployment Tasks
- Automatically deploy Docker images
- Rollout update in Kubernetes
- Auto-scale backend pods
Simple Explanation
CI automates code testing and integration.
CD (Delivery) automates preparing builds for release.
CD (Deployment) automates releasing the app to production.
CI/CD {Jenkins & GitLabs}:
Jenkins :
- open-source automation sever
- orchestrate software dev
- jenkins looks for changes in code and triger test stages , builds and even pushes code
- Build : here we check code complaints , executable application
- Test : unit test , integration testing , end to end testing
- Deploy stage : pushing the application to cloud environment
- jenkins can easily integrated with any tool like , version control , cloud plotforms {AWS , Azure} , testing frameworks , notification tools
- Monitors source code repositories and triggers pipelines on events (commit, PR, schedule, webhook).
- Executes pipelines consisting of stages such as:
Build stage
- Compile code
- Run static code analysis (code quality / linting)
- Produce artifacts (JAR, Docker image, binary, etc.)
Test stage
- Unit tests
- Integration tests
- End-to-end (E2E) tests
Deploy stage
- Deploys applications to environments:
- Cloud (AWS, Azure, GCP)
- On-prem servers
- Kubernetes / Docker platforms
- Integrates easily with:
- Version control (GitHub, GitLab, Bitbucket)
- Cloud providers (AWS, Azure, GCP)
- Build tools (Maven, Gradle, npm)
- Testing frameworks (JUnit, Selenium, Cypress)
- Notification tools (Slack, Email, Teams)
GitLabs :
- while Jenkins is automation plotform, gitlabs provides all in one plotform like CI/CD
- here we define ci in the repo inside yaml file{gitlab-ci,yaml}
why should i use jenkins with gitlab , when gitlab provides all features ?
Existing Jenkins infrastructure
Many organizations already have:
- Large, complex Jenkins pipelines
- Custom plugins
- Enterprise integrations
- Legacy workflows
Migrating everything to GitLab CI is:
- Risky
- Time-consuming
- Expensive
So GitLab is used only as source control,and Jenkins handles CI/CD.
Advanced customization
Jenkins offers:
- Extremely flexible pipelines (Groovy DSL)
- Thousands of plugins
- Custom agents & infrastructure control
Some enterprises need this level of control.
GitLab → Jenkins triggering
GitLab can trigger Jenkins jobs using:
- Webhooks
- Jenkins API
- GitLab CI jobs calling Jenkins
So:
GitLab manages code → Jenkins runs pipelines
Diffrence btw github actions and gitLabs
| Feature | GitHub Actions | GitLab CI |
|---|---|---|
| Repo hosting | GitHub only | GitLab only |
| CI/CD | Yes | Yes |
| Issue tracking | Yes | Yes |
| Container registry | Limited | Built-in |
| Security scanning | Basic | Advanced built-in |
| DevOps lifecycle | Partial | Complete (end-to-end) |
What is a Webhook?
A webhook is an HTTP callback mechanism.
It automatically sends a real-time HTTP request to another system when a specific event occurs.
In simple terms:
“Something happened → notify another system immediately.”
How it works (flow)
- An event occurs
(e.g., git push, merge, payment success, issue created)
- The source system sends an HTTP POST request to a configured URL
- The target system receives it and executes an action
GitHub/GitLab → (Webhook HTTP POST) → Jenkins /Server / API
Ansible :
A open source automation tool used to config servers ,deploy apps and ,manage infra
Ansible is mainly used for:
- Server setup (installing packages, configuring services)
- Deploying applications
- Managing cloud infrastructure
- DevOps automation
- CI/CD pipelines
- Infrastructure as Code (IaC)
Example: yaml file
- hosts: webservers
become: yes
tasks:- name: Install nginx
apt:
name: nginx
state: present
- name: Install nginx
then run : ansible-playbook install-nginx.yml




