Ravindra BagaleCourses & study guides मराठी

How to Read This Course

DevOps

0.5 Conventions: Why → What → How

Why: the problem

Imagine a message at 11 p.m.: "The Paytm offers page is down." A junior engineer panics and starts typing random commands. A senior engineer stays calm and asks three questions in order. Why: what problem do users see, and why does it matter? What: which part is involved, and what do these words mean? How: which exact commands will show the cause and fix it? This Why, What, How order is not only how this course is written. It is how good engineers think at work. When you face something new, a tool, an error or an interview question, you can use the same three steps. In this lesson you will practise the pattern on three small real problems on your own machine: a full disk, a busy port and a container that keeps restarting. Each time you will write the Why, the What and the How before you touch the keyboard.

What we will build

You will create three small problems on purpose and solve each one with the Why, What, How pattern. Problem 1: a disk that fills up. Problem 2: a port that is already in use. Problem 3: a container that keeps crashing. For each one you will write a three-line plan, run the commands and record the fix.

What: every term in plain English

  • Why — The problem and the reason it matters to users or the business.
  • What — The parts and words involved, explained simply.
  • How — The exact steps and commands, in order, with the output you expect.
  • df — Disk free. Shows how full each disk is.
  • du — Disk usage. Shows which folders use the space.
  • ss — Socket statistics. Shows which program uses which port.
  • Restart loop — A container that starts, crashes and starts again and again.
  • Root cause — The real reason behind a problem, not just the symptom.
Write the three-line plan first Make a fake full disk safely How: see the disk How: find the big folder How: fix and check
Why, What, How on three real problems

How: step by step

  1. Write the three-line plan first

    printf "WHY: users see errors because the disk is full\nWHAT: df shows disks, du shows folders\nHOW: df -h, du -sh, delete old files\n" | tee plan.txt
    

    What it does: Writing the plan stops random typing.

    Output

    WHY: users see errors because the disk is full
    WHAT: df shows disks, du shows folders
    HOW: df -h, du -sh, delete old files
    
  2. Make a fake full disk safely

    mkdir -p ~/devops-lab/ch0-practice && cd ~/devops-lab/ch0-practice
    fallocate -l 500M bigfile.log && ls -lh bigfile.log
    

    What it does: Creates one 500 MB file to play with. Nothing real is harmed.

    Output

    -rw-rw-r-- 1 ravi ravi 500M Oct 25 10:12 bigfile.log
    
  3. How: see the disk

    df -h /
    

    What it does: Shows size, used and free space of the main disk.

    Output

    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1        30G   18G   12G  60% /
    
  4. How: find the big folder

    du -sh ~/devops-lab/* | sort -h | tail -3
    

    What it does: Lists folders by size, biggest last.

    Output

    4.0K  /home/ravi/devops-lab/notes
     52K  /home/ravi/devops-lab/menu
    501M  /home/ravi/devops-lab/ch0-practice
    
  5. How: fix and check

    rm bigfile.log && df -h / | tail -1
    

    What it does: Deletes the big file and checks space came back.

    Output

    /dev/sda1        30G   17G   13G  57% /
    

Example 1: Problem 2 with the pattern: a port that is already in use

Stack. Python 3 http.server, iproute2 ss

Goal. Problem 2 with the pattern: a port that is already in use.

plan.txt

WHY:  the new web app cannot start, so users get no page
WHAT: a port is a numbered door; only one program can use it
HOW:  find who uses the port with ss, stop it, start the app

terminal

python3 -m http.server 8000 &
python3 -m http.server 8000
sudo ss -ltnp | grep :8000
kill %1
python3 -m http.server 8000 &
curl -s -o /dev/null -w "%{http_code}\n" localhost:8000

What each line does

  • python3 -m http.server 8000 & — Starts a tiny web server on port 8000 in the background.
  • second http.server 8000 — Tries the same port and fails on purpose.
  • ss -ltnp | grep :8000 — Shows the program and its process ID on port 8000.
  • kill %1 — Stops background job number 1.
  • curl ... %{http_code} — Prints 200 when the new server answers.

Green output

OSError: [Errno 98] Address already in use
LISTEN 0 5 0.0.0.0:8000 0.0.0.0:* users:(("python3",pid=4121,fd=3))
[1]+  Terminated   python3 -m http.server 8000
200

Expected result. You did not guess. The plan said "find who uses the port", ss showed it, and the fix took one command.

Example 2: Problem 3 with the pattern: a container that keeps restarting

Stack. Docker 26, Alpine 3.20

Goal. Problem 3 with the pattern: a container that keeps restarting.

plan.txt

WHY:  the service flaps, so some user requests fail
WHAT: a restart loop means the main process exits; the exit code and logs tell why
HOW:  docker ps, docker logs, docker inspect exit code, fix the command

terminal

docker run -d --name flappy --restart always alpine:3.20 sh -c "echo starting; exit 3"
sleep 5
docker ps --filter name=flappy --format "{{.Status}}"
docker logs flappy | tail -2
docker inspect flappy --format "exit={{.State.ExitCode}} restarts={{.RestartCount}}"

What each line does

  • --restart always — Docker restarts the container every time it stops.
  • sh -c "echo starting; exit 3" — A process that exits with code 3 on purpose.
  • docker ps ... Status — Shows "Restarting".
  • docker logs flappy — Shows what the process printed before dying.
  • docker inspect ... ExitCode — The exit code is the biggest clue.

Green output

Restarting (3) 1 second ago
starting
starting
exit=3 restarts=4

Expected result. The pattern led you straight to the logs and the exit code. In a real app the logs would show, for example, a missing database password.

Example 3: Use the pattern for an interview answer

Stack. Docker volumes

Goal. Use the pattern for an interview answer.

answer.txt

Q: What is a Docker volume?

WHY:  containers lose their files when they are deleted; databases need data to stay
WHAT: a volume is storage managed by Docker that lives outside the container
HOW:  docker volume create data
      docker run -d -v data:/var/lib/mysql mysql:8.4
      delete the container, run a new one with the same volume, the data is still there

terminal

docker volume create data
docker run --rm -v data:/d alpine:3.20 sh -c "echo saved > /d/x.txt"
docker run --rm -v data:/d alpine:3.20 cat /d/x.txt

What each line does

  • WHY line — Starts with the problem. Interviewers like this.
  • WHAT line — One plain definition.
  • HOW lines — Real commands prove you have done it.
  • docker volume create data — Makes a named volume.
  • second docker run ... cat — A brand new container still reads the file.

Green output

data
saved

Expected result. Your answer is short, starts with a real problem and ends with proof. This is the shape of a strong interview answer.

Verify: did it work?

  1. Check the plans exist

    ls ~/devops-lab/ch0-practice/*.txt 2>/dev/null || ls plan.txt
    

    What it does: Your plans are part of your notes.

    Output

    plan.txt
    
  2. Check nothing is still flapping

    docker ps -a --filter name=flappy --format "{{.Names}} {{.Status}}"
    

    What it does: Shows the flappy container before cleanup.

    Output

    flappy Restarting (3) 2 seconds ago
    

When it is red 1

fallocate: fallocate failed: Operation not supported

Cause. Some file systems (like some WSL mounts) do not support fallocate.

Fix, step by step

  1. Use dd instead: dd if=/dev/zero of=bigfile.log bs=1M count=500.
  2. Work inside your Linux home folder, not /mnt/c.

When it is red 2

du: cannot read directory '/var/lib/docker': Permission denied

Cause. Some folders belong to root.

Fix, step by step

  1. Run sudo du -sh /var/lib/docker.
  2. For Docker space use docker system df instead.

When it is red 3

Error response from daemon: Conflict. The container name "/flappy" is already in use

Cause. An old container with the same name exists.

Fix, step by step

  1. Run docker rm -f flappy.
  2. Run the docker run command again.

Cleanup

  1. Remove the flapping container

    docker rm -f flappy
    

    What it does: Stops the restart loop and deletes the container.

    Output

    flappy
    
  2. Remove the volume

    docker volume rm data
    

    What it does: Deletes the practice volume.

    Output

    data
    
  3. Delete the practice folder

    rm -rf ~/devops-lab/ch0-practice
    

    What it does: Removes only the files you made in this lesson. Your other labs stay.

    Output

    (no output means it worked)
    

Ravindra Bagale's Tip

Before you touch the keyboard, write three short lines: Why, What, How. You stay calm, and the same answer looks strong in an interview!

Practice tasks

Easy Plan before you type

Why: Writing first is a habit.

What to do: Write a WHY/WHAT/HOW plan for "the website is slow".

How:
  1. Three lines only.

Check: Your HOW has at least two real commands.

Medium Docker disk usage

Why: Docker eats disk quietly.

What to do: Use the pattern on docker system df.

How:
  1. WHY: disk fills.
  2. WHAT: images, containers, volumes, cache.
  3. HOW: docker system df, docker image prune.

Check: You can say how much space Docker uses.

Hard Real restart reason

Why: Exit codes have meanings.

What to do: Make containers exit with 1, 137 and 143 and explain each.

How:
  1. exit 1 in sh.
  2. docker kill sends 137.
  3. docker stop sends 143.

Check: You can explain each exit code.

Easy Say Why, What, How 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 Why, What, How 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, pick one problem you faced on a computer this month (slow Wi-Fi, a full phone, an app that crashed). Write its Why, What and How in three lines, then the commands or steps you would use. Do the same for the question "What is Git?".

Recap

  • Why: the problem and why it matters.
  • What: the parts and words, in plain English.
  • How: exact commands, in order, with expected output.
  • Use it for errors, new tools and interview answers.
  • Write the three-line plan before you type.

FAQ

Is Why, What, How only for this course?

No. It works for debugging, learning new tools, writing docs and interviews.

What if I do not know the What?

Then the plan shows you what to read first. That is useful too.

Should the How always be commands?

For DevOps, yes, as much as possible. Commands can be checked.

How long should the plan be?

Three lines. If it is longer, split the problem.

Do seniors really do this?

Yes. Incident runbooks at most companies follow the same shape: impact, components, steps.

Interview questions

  1. How do you approach a production issue?

    Understand the user impact (why), find the components involved (what), then check logs, metrics and recent changes step by step (how), fix, and write a post-mortem.

  2. A server disk is full. What do you do?

    df -h to find the disk, du -sh to find the folder, clean logs or old images safely, then add log rotation and alerts.

  3. A port is already in use. How do you find the process?

    sudo ss -ltnp or lsof -i :PORT, then stop or move that process.

  4. How do you debug a restarting container?

    docker logs, docker inspect for the exit code, check config and dependencies, then fix and redeploy.

  5. How do you structure answers in interviews?

    Start with the problem, give a short definition, then a real example with commands.

Quick quiz

Q1. What are the three steps of the pattern?

Why, What, How.

Q2. Which command shows how full a disk is?

df -h.

Q3. Which command shows who uses a port?

ss -ltnp (with sudo for process names).

Q4. What is the best first clue for a restarting container?

docker logs and the exit code from docker inspect.

Q5. Why write the plan before typing?

It stops random commands and keeps you calm.

Did you understand? Let us try it once more.