Ravindra BagaleCourses & study guides मराठी

How to Read This Course

DevOps

0.1 Why DevOps after (or beside) AWS

Why: the problem

You finished the AWS course. You can start an EC2 server, open a port and attach an IAM role. Good. Now think of a real team at Swiggy. Developers change the menu service twenty times a day. If each change needs a person to log in to a server, copy files and restart the app, that person becomes the slowest part of the company. Mistakes happen too: a wrong file, a missed step, a server that is different from the others. AWS gives you the servers. DevOps is how you ship changes to those servers safely, quickly and the same way every time. It is a way of working plus a set of tools: Git to track changes, Docker to package the app, CI/CD to build and test it automatically, Terraform to create servers from code, Kubernetes to run many copies, and monitoring to know when something breaks. In this lesson you will feel the difference yourself. You will deploy a tiny web page by hand, then deploy it again with a script and with Docker, and count the steps and the mistakes.

What we will build

You will put a one-line web page on a Linux machine three ways. First by hand, typing every step. Second with a small Bash script that does the same steps. Third with a Docker container that carries the page and the web server together. At the end you will compare: how many commands, how long, and how easy it is to repeat on a second machine.

What: every term in plain English

  • AWS — Amazon Web Services. It rents you servers, storage and networks by the hour.
  • DevOps — A way of working where the people who write code and the people who run it share the work, and automate the boring, risky steps.
  • Deploy — Putting a new version of the app on the server so users get it.
  • Manual deploy — A human types every step. Slow and easy to get wrong.
  • Script — A text file with commands. The computer runs them in order, the same way every time.
  • Container — A package with the app and everything it needs, so it runs the same on every machine.
  • Repeatable — You can do it again and get the same result.
  • nginx — A popular, free web server. It sends web pages to browsers.
Make your lab folder Install nginx by hand Write the page by hand Start nginx Open the page Count what you did
Deploy by hand, then by script, then by container

How: step by step

  1. Make your lab folder

    mkdir -p ~/devops-lab && cd ~/devops-lab && pwd
    

    What it does: One folder for every lab in this course. Easy to find, easy to clean.

    Output

    /home/ravi/devops-lab
    
  2. Install nginx by hand

    sudo apt update && sudo apt install -y nginx
    

    What it does: Downloads the package list, then installs the nginx web server.

    Output

    Reading package lists... Done
    Setting up nginx (1.18.0-6ubuntu14.4) ...
    Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service
    
  3. Write the page by hand

    echo "Swiggy menu v1" | sudo tee /var/www/html/index.html
    

    What it does: Puts one line of text into the default web page file.

    Output

    Swiggy menu v1
    
  4. Start nginx

    sudo systemctl enable --now nginx
    

    What it does: Starts nginx now and also at every boot.

    Output

    (no output means it worked)
    
  5. Open the page

    curl -s localhost
    

    What it does: Asks the local web server for the page, like a browser would.

    Output

    Swiggy menu v1
    
  6. Count what you did

    history | tail -5
    

    What it does: Shows your last commands. Each one is a step a human can forget.

    Output

    101  sudo apt update && sudo apt install -y nginx
    102  echo "Swiggy menu v1" | sudo tee /var/www/html/index.html
    103  sudo systemctl enable --now nginx
    104  curl -s localhost
    

Example 1: Deploy by hand and time it

Stack. Ubuntu 22.04, nginx 1.18

Goal. Deploy by hand and time it. This is the "old way".

terminal

time (
  sudo apt install -y nginx
  echo "Swiggy menu v2" | sudo tee /var/www/html/index.html
  sudo systemctl restart nginx
  curl -s localhost
)

What each line does

  • time ( ... ) — Runs everything inside the brackets and prints how long it took.
  • apt install -y nginx — Installs nginx. -y says yes to the question.
  • tee /var/www/html/index.html — Writes the new page. sudo is needed because the folder belongs to root.
  • systemctl restart nginx — Restarts the web server so it serves the new file.
  • curl -s localhost — Checks the page. -s hides the progress bar.

Green output

nginx is already the newest version (1.18.0-6ubuntu14.4).
Swiggy menu v2
Swiggy menu v2

real    0m2.418s
user    0m0.512s
sys     0m0.210s

Expected result. It works, but only because you typed four lines correctly. On ten servers you would type forty lines.

Example 2: The same deploy as a Bash script

Stack. Bash 5, Ubuntu 22.04

Goal. The same deploy as a Bash script. This is the first step of automation.

deploy.sh

#!/usr/bin/env bash
set -euo pipefail
VERSION="${1:-v3}"
sudo apt-get install -y nginx > /dev/null
echo "Swiggy menu ${VERSION}" | sudo tee /var/www/html/index.html > /dev/null
sudo systemctl restart nginx
if curl -s localhost | grep -q "${VERSION}"; then
  echo "DEPLOY OK: ${VERSION}"
else
  echo "DEPLOY FAILED" && exit 1
fi

terminal

chmod +x deploy.sh
./deploy.sh v3

What each line does

  • #!/usr/bin/env bash — Tells Linux to run this file with Bash.
  • set -euo pipefail — Stop at the first error. Do not continue half done.
  • VERSION="${1:-v3}" — Takes the version from the first argument, or uses v3.
  • > /dev/null — Hides noisy output so you see only the result.
  • grep -q "${VERSION}" — Checks that the new version is really being served.
  • exit 1 — Marks the script as failed so a person or a tool notices.
  • chmod +x deploy.sh — Makes the file runnable by you..

Green output

DEPLOY OK: v3

Expected result. One command now does the whole deploy and checks itself. A teammate can run the same file and get the same result.

Example 3: The same page in a Docker container

Stack. Docker 26, nginx 1.27-alpine

Goal. The same page in a Docker container. The app and the server travel together.

Dockerfile

FROM nginx:1.27-alpine
COPY index.html /usr/share/nginx/html/index.html

index.html

Swiggy menu v4 (from a container)

terminal

sudo systemctl stop nginx
docker build -t menu:v4 .
docker run -d --name menu -p 80:80 menu:v4
curl -s localhost

What each line does

  • FROM nginx:1.27-alpine — Start from the official small nginx image, pinned to a version.
  • COPY index.html ... — Put our page inside the image.
  • systemctl stop nginx — Frees port 80 that the host nginx was using.
  • docker build -t menu:v4 . — Builds an image named menu with tag v4 from this folder.
  • docker run -d -p 80:80 — Runs it in the background. Host port 80 goes to container port 80.
  • curl -s localhost — Checks the page from the container.

Green output

[+] Building 3.1s (7/7) FINISHED
 => naming to docker.io/library/menu:v4
3f1c9a7e2b...
Swiggy menu v4 (from a container)

Expected result. The image menu:v4 runs the same on your laptop, on EC2 or on a teammate's machine. This is why every DevOps chapter after this uses containers.

Verify: did it work?

  1. Check the container is up

    docker ps --format "table {{.Names}}\t{{.Image}}\t{{.Status}}"
    

    What it does: Shows the running container and its image.

    Output

    NAMES   IMAGE     STATUS
    menu    menu:v4   Up 20 seconds
    
  2. Compare the three ways

    wc -l deploy.sh Dockerfile
    

    What it does: Counts lines. Fewer, tested lines mean fewer mistakes.

    Output

    11 deploy.sh
     2 Dockerfile
    13 total
    

When it is red 1

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

Cause. Something else already uses port 80, often the host nginx or an old container.

Fix, step by step

  1. Run sudo ss -ltnp | grep :80 to see who uses it.
  2. Stop it: sudo systemctl stop nginx or docker rm -f menu.
  3. Start your web server again.

When it is red 2

tee: /var/www/html/index.html: Permission denied

Cause. You wrote to a root folder without sudo.

Fix, step by step

  1. Put sudo before tee, not before echo.
  2. Run the command again.
  3. Never open the folder to everyone; use sudo for this one write.

When it is red 3

docker: permission denied while trying to connect to the Docker daemon socket

Cause. Your user is not in the docker group yet.

Fix, step by step

  1. Run sudo usermod -aG docker $USER.
  2. Log out and log in again (or run newgrp docker).
  3. Run docker ps to check.

Cleanup

  1. Remove the container

    docker rm -f menu
    

    What it does: Stops and deletes the container.

    Output

    menu
    
  2. Remove the image

    docker rmi menu:v4
    

    What it does: Deletes the image you built.

    Output

    Untagged: menu:v4
    Deleted: sha256:3f1c9a7e2b...
    
  3. Stop host nginx

    sudo systemctl disable --now nginx
    

    What it does: Stops nginx and keeps it off after reboot.

    Output

    Removed /etc/systemd/system/multi-user.target.wants/nginx.service.
    

Ravindra Bagale's Tip

AWS is the house (the server). DevOps is the habit of keeping that house clean every day. First do it by hand, then write a script, then use a container. Feel the difference yourself!

Practice tasks

Easy Change the version

Why: Small change, full deploy. That is daily DevOps work.

What to do: Run ./deploy.sh v9 and check the page.

How:
  1. ./deploy.sh v9
  2. curl -s localhost

Check: The page says Swiggy menu v9.

Medium Make the script fail on purpose

Why: A good script must say FAILED loudly.

What to do: Edit deploy.sh so the grep looks for a wrong word, then run it.

How:
  1. Change grep to look for "xyz".
  2. Run ./deploy.sh.
  3. echo $? should print 1.

Check: You see DEPLOY FAILED and exit code 1.

Hard Two containers, two versions

Why: Teams often run old and new side by side.

What to do: Run menu:v4 on port 8081 and a new menu:v5 on port 8082.

How:
  1. Build menu:v5 with new text.
  2. docker run -d -p 8081:80 menu:v4 and -p 8082:80 menu:v5.
  3. curl both ports.

Check: Each port shows its own version.

Easy Say AWS and DevOps in two lines

Why: If you can say it simply, you understand it. Interviewers want the short version first.

What to do: Write two short lines about AWS and DevOps for a friend who is new to IT.

How:
  1. Write what problem it solves.
  2. Write one command or file you used for it.
  3. Read it aloud.

Check: Your friend understands it without asking a question.

Easy Run the commands again from memory

Why: Typing from memory makes the commands stick. Copy-paste does not.

What to do: Close this page and run the main steps of this lesson again.

How:
  1. Open a fresh terminal.
  2. Type each command yourself.
  3. Open the page only when stuck.

Check: You got the same green output without copying.

Medium Break it on purpose

Why: You must know the red message by face. In a real job there is no time to read slowly.

What to do: Cause one error from the "When it is red" part of this lesson and fix it.

How:
  1. Follow one error section.
  2. Copy the exact message into your notes.
  3. Write the fix in one line.

Check: You fixed it using only your notes.

Medium Write a one-page note

Why: A short note in your own words is the best revision.

What to do: Write a note page for this lesson in ~/devops-lab/notes.md.

How:
  1. Title, why, the commands, one error and its fix.

Check: A classmate can follow your note alone.

Hard Explain it like an interview

Why: Interviewers want real stories, not definitions.

What to do: Record a 60 second answer about this lesson on your phone.

How:
  1. Say the problem, what you did, the command you ran, and one error you hit.

Check: Your answer has a real command and a real error message.

Hard Draw the flow top to bottom

Why: A drawing shows the order of things.

What to do: Draw this lesson as boxes from top to bottom on paper.

How:
  1. One box per step.
  2. Write the command next to each box.

Check: Each box matches a step you really ran.

Easy Teach it to someone

Why: Teaching shows the gaps in your own understanding.

What to do: Explain this lesson to a friend or family member in five minutes.

How:
  1. Use one real app as the example (Swiggy, Netflix, Paytm).

Check: They can tell you back the main idea.

Homework: try at home

Try at home

At home, run all three ways again on a fresh Ubuntu VM or an EC2 t3.micro. Write the time each way took and how many commands you typed. Then change the page text to v5 and see which way is fastest to repeat.

Recap

  • AWS rents servers; DevOps is how you ship to them safely and often.
  • A manual deploy is slow and error prone.
  • A script makes the steps repeatable and self-checking.
  • A container carries the app and its server together.
  • Every later chapter builds on these three ideas.

FAQ

Do I need DevOps if I know AWS well?

Yes. AWS skills create servers. DevOps skills ship code to them every day without breaking things.

Is DevOps a job title or a culture?

Both. It started as a culture. Today many companies also hire "DevOps Engineers".

Should I learn Docker before Kubernetes?

Yes. Kubernetes runs containers, so you need to understand containers first.

Can I do this course on Windows?

Yes, use WSL2 with Ubuntu. Lesson 0.2 shows how.

Is Bash still needed when we have tools?

Yes. Every tool, from Jenkins to Kubernetes, runs shell commands underneath.

Interview questions

  1. What is DevOps in one line?

    A way of working where development and operations share ownership and automate building, testing and releasing software.

  2. How is DevOps different from AWS?

    AWS is a cloud provider. DevOps is a set of practices and tools that can use AWS, Azure or your own servers.

  3. Why automate a deploy?

    To make it fast, repeatable and less error prone, so teams can release many times a day.

  4. Why are containers popular in DevOps?

    They package the app with its dependencies, so it runs the same in every environment.

  5. Give an example of a manual step you automated.

    For example, a Bash script that installed nginx, copied the page, restarted it and checked the result with curl.

Quick quiz

Q1. What does AWS give you, and what does DevOps add?

AWS gives servers and services. DevOps adds a safe, repeatable way to ship changes to them.

Q2. Why is a manual deploy risky?

A human can skip or mistype a step, and each server can end up different.

Q3. What does set -euo pipefail do?

Stops the script at the first error.

Q4. Why do we pin nginx:1.27-alpine and not latest?

So the same image is used every time.

Q5. Which deploy is easiest to repeat on a new machine?

The Docker one, because the image carries the app and the server.

Did you understand? Let us try it once more.