DevOps Kit Lessons Lesson 13 of 18

Checking your sign-in…

🔒

This lesson is in Phase 2 — ₹799, one-time

Pay once with UPI, card or netbanking. Keep it forever. Your progress saves, so you can stop and come back.

← Back to all lessons

Cheat Sheets — Commands You Will Actually Use

Phase 2 · The Rest of DevOps

What this is and why it matters

This is your quick reference: keep it open while you practise, and look things up here when you need them.

In real work, nobody memorises every tool — the skill is knowing where to look and checking the result.

Every line pairs one tool with what it does and what good output looks like, so a wrong result stands out at once.

A cheat sheet is a one-page reminder card. Think of the formula sheet you get in an exam. You do not memorise every formula. You keep the sheet open, find the one you need, and use it.

All commands below are standard, well-known commands for their tools, written for a Linux terminal (Ubuntu/Debian directly, or WSL2 Ubuntu on Windows). systemctl commands work on systemd Linux only — on Docker Desktop, start the app instead.

Test status: syntax-checked only. These commands were checked for correct syntax, but this sheet does not promise any of them was run end-to-end on a real machine. Try each one yourself and read what it prints.

How to read this file: find the tool you are working with, read the WHAT and the WHY first, then type the command. After you press Enter, compare what you see with the "You should see" lines. If it looks different, that is information, not failure — read the error line and fix that one thing.

Reference tool
This page supports every topic — use it whenever you are stuck. It has no ladder of its own.

Words you need first

  • A command is one line of text you type, then press Enter.
  • The terminal is the black window where you type commands. A shell is the program inside that window that reads your typed commands. If you have never opened one, do Lesson 0 first — it shows how.
  • A folder is a named box that holds files. Your computer is full of folders inside folders.
  • A file is one named thing inside a folder, like one page in a box.
  • A flag is a short extra word after a command, starting with - or --. It changes what the command does.
  • A placeholder looks like <file> or <name>. It is not a real word. You replace it with your real file name or real name. Never type the < and > brackets.
  • A container is a small sealed box that runs one program, with everything that program needs inside the box.
  • An image is the packed box before it runs. A container is the image running.
  • A service is a program that runs in the background and waits for requests, like a shopkeeper waiting behind a counter.

The three words every command uses

Every command in this lesson is built from the same three ideas.

  1. The program name first. docker, git, kubectl, ls. This is the tool you are talking to.
  2. The action second. ps, status, get, logs. This is what you ask the tool to do.
  3. The details last. File names, folder names, flags. These say which thing, and how.

Example: docker ps -a.

  • docker — the program. The tool that runs containers.
  • ps — the action. Short for "process status". It means "list the containers".
  • -a — the flag. It means "all". Without it you see only running containers. With it you also see stopped ones.

If a command ever looks like a wall of letters, split it into those three parts and read it left to right. That is the whole trick.

Making files

What it is

A text editor is a program that lets you write words into a file.

nano is the simplest editor. It opens inside the terminal itself.

cat is a program that prints a file's words onto the screen. With a > sign it can write words into a file instead.

Why we do it

Every project in this kit needs files: a web page, a recipe file, a settings file. You have to be able to make one before you can do anything else.

Command — open a file to write in it

Try it Yourself »Open the practice terminal and run it yourself — nothing installs. Included with Phase 2. Simulation — practice version. The real thing is the same commands, in your own terminal.
Command
nano <file>

Word by word:

  • nano — the editor program.
  • <file> — placeholder. Replace it with the real file name, for example nano index.html. If the file does not exist yet, nano makes an empty one with that name.

You should see: the terminal screen clears and shows your file's text, with a list of key shortcuts at the bottom.

To save: press Ctrl+O, then press Enter. "Save" means "write what I typed into the file on the disk".

To leave: press Ctrl+X. "Leave" means "close the editor and go back to the normal terminal".

If it breaks: if Ctrl+O asks "File Name to Write", it is asking you to confirm the name. Press Enter to accept the name shown.

Command — write lines into a file without opening an editor

Command
cat > <file> << 'EOF'

Word by word:

  • cat — the program that prints or writes text.
  • > — this sign means "send the text into the file that follows, instead of onto the screen".
  • <file> — placeholder. The file to write into, for example index.html.
  • << 'EOF' — this means "read the lines I type next, until I type a line that says only EOF". EOF stands for "end of file". It is a marker word, not a file.

How to use it: type the command, press Enter, then type your lines one by one. When you are done, type EOF alone on a line and press Enter. The file is written.

You should see: nothing while you type. After the EOF line, you are back at the normal terminal prompt. That silence means it worked.

If it breaks: if you never type the closing EOF line, the terminal keeps waiting for more lines. Type EOF alone on a line. If you typed the wrong file name, you made a file with the wrong name — delete it and try again.

The YAML warning — spaces, never Tab

YAML is a settings-file format. Files ending in .yml or .yaml are YAML files. YAML uses spaces at the start of a line to show which lines belong together. This is called indentation.

A Tab key press looks like spaces on screen, but it is a different character, and YAML refuses it. So in .yml files, press the space bar for indentation. Never press Tab.

You should see: if you used a Tab by mistake, the error names the line number. Go to that line, delete the Tab, and type spaces.

Linux

Linux is the operating system — the base program that runs the computer and lets other programs run on it. These commands ask Linux simple questions about files and programs.

Command — show which folder you are in

Command
pwd

Word by word:

  • pwd — short for "print working directory". "Working directory" means "the folder I am standing in right now".

You should see: one line, a folder path, for example /home/learner/devops-practice. That is where you are.

Command — list files, including hidden ones

Command
ls -la

Word by word:

  • ls — short for "list". It lists the files in the folder you are in.
  • -l — the flag for "long". It shows extra detail per file: size, date, permissions.
  • -a — the flag for "all". It also shows hidden files. A hidden file is one whose name starts with a dot, like .github. Linux hides dot-files from a plain ls.

You should see: one line per file, starting with letters like drwxr-xr-x or -rw-r--r--, then a size, a date, and a name.

Command — move into a folder

Command
cd <folder>

Word by word:

  • cd — short for "change directory". "Directory" is the old word for folder.
  • <folder> — placeholder. The folder to move into, for example cd my-site.

You should see: nothing. cd prints nothing when it works. That silence is normal. Type pwd to check where you landed.

If it breaks: "No such file or directory" means the folder does not exist, or you typed its name wrong. Check the spelling with ls.

Command — make a new folder

Command
mkdir <name>

Word by word:

  • mkdir — short for "make directory".
  • <name> — placeholder. The name of the new folder, for example mkdir my-site.

You should see: nothing when it works. Type ls to see the new folder listed.

Command — print a file's contents

Command
cat <file>

Word by word:

  • cat — the program that prints text.
  • <file> — placeholder. The file to print, for example cat index.html.

You should see: the file's words printed on the screen.

Command — find a word inside a file

Command
grep <word> <file>

Word by word:

  • grep — the program that searches text.
  • <word> — placeholder. The word to look for, for example grep hello index.html.
  • <file> — placeholder. The file to search in.

You should see: only the lines that hold the word, printed on the screen. For example, grep hello index.html prints each line in index.html that holds the word hello. If nothing prints, the word is not in the file. That is a result, not an error.

Command — make a file runnable

Command
chmod +x <file>

Word by word:

  • chmod — short for "change mode". It changes what people are allowed to do with a file.
  • +x — the flag that means "add execute". "Execute" means "allowed to run as a program".
  • <file> — placeholder. The file to change, for example chmod +x kit-doctor.sh.

Why: a script file is just text until you give it the "run" right. Without +x, Linux answers "permission denied" when you try to run it.

You should see: nothing when it works. Run ls -l <file> and look for an x in the letters at the start of the line.

Command — list running programs

Command
ps aux

Word by word:

  • ps — short for "process status". A "process" is one running program.
  • a — show programs run by all users, not only yours.
  • u — show them in a user-friendly way, with the user name and extra columns.
  • x — also show programs with no terminal window attached.

You should see: a table. The columns that matter are PID (the program's number — every running program gets a unique number), %CPU (how much of the processor it uses), %MEM (how much memory it uses), and COMMAND (the program's name).

Command — watch live CPU and memory use

Command
top

Word by word:

  • top — the program that shows the busiest programs, live, updating every few seconds.

You should see: a full-screen table that keeps changing. The top lines use the most CPU.

To leave: press q. If you do not press q, top keeps running and you cannot type other commands.

Command — show disk space

Command
df -h

Word by word:

  • df — short for "disk free".
  • -h — the flag for "human-readable". It shows sizes like 20G instead of a huge count of bytes.

You should see: a table with Size, Used, Avail (free space left), and Mounted on (which disk). If Avail is near zero, the disk is full.

Command — show memory use

Command
free -h

Word by word:

  • free — the program that shows free memory.
  • -h — human-readable, as above.

You should see: a table with total, used, and free memory. If free is very small, the machine is short of memory.

Commands — start and check a service

Command
sudo systemctl start <service>
sudo systemctl status <service>

Word by word:

  • sudo — short for "superuser do". It means "run this with administrator power". Your normal account cannot start system services; sudo asks for your password and lends you the power for one command.
  • systemctl — the program that controls services on Linux systems that use systemd. systemd is the part of Linux that starts and watches background programs.
  • start — the action: begin running the service.
  • status — the action: show whether it is running and what it printed lately.
  • <service> — placeholder. The service's name, for example nginx or docker.

You should see for status: a block of text. The line that matters says Active: active (running) if it works, or Active: inactive or failed if it does not.

Important: systemctl only works on Linux that uses systemd. On Docker Desktop, there is no systemd — start the app the Docker way instead. If systemctl answers "System has not been booted with systemd", you are on a machine without it. That is not an error in your typing.

Git

Git is a tracker for your files. It remembers every saved version, so you can go back, try a change on a side copy, and share your work.

  • A repository is a folder Git is tracking.
  • A commit is one saved version, with a message saying what changed.
  • A branch is a side copy of your work, so you can try something without touching the main copy.

Command — start tracking a folder

Command
git init

Word by word:

  • git — the tracker program.
  • init — short for "initialise". It means "start tracking this folder".

You should see: Initialized empty Git repository in .... Run it once, inside the folder you want to track. Never run it inside a folder that is already tracked.

Command — copy a repository from GitHub to your machine

Command
git clone <address>

Word by word:

  • clone — make a full copy.
  • <address> — placeholder. The web address of the repository, for example the address GitHub shows on the repository page.

You should see: lines saying it is copying, then a new folder with the repository's name.

Command — tell Git who you are (once)

Command
git config user.name "Your Name"
git config user.email "you@example.com"

Word by word:

  • config — change a setting.
  • user.name — the setting for your name. Replace "Your Name" with your real name, keeping the quotes.
  • user.email — the setting for your email. Replace you@example.com with your real email.

Why: every commit you save is stamped with your name and email, so people know who made it. You set this once per machine. Git stores it in a small settings file in your home folder.

You should see: nothing when it works.

Command — show what changed

Command
git status

You should see: a list of files you changed, files you added, and files Git does not track yet. Read this before every save. It is your "what is about to happen" check.

Command — stage all changes

Command
git add .

Word by word:

  • add — the action: put files into the staging area.
  • . — the dot means "this folder and everything in it". So git add . stages every changed file in this folder.

"Staging" means "putting files in a waiting pile for the next save". Nothing is saved yet. It is like putting items on the counter before paying.

Command — save changes with a message

Command
git commit -m "message"

Word by word:

  • commit — save the staged files as one version.
  • -m — the flag for "message". It lets you write the message on the same line.
  • "message" — placeholder. Replace it with a short message saying what changed, for example git commit -m "Add home page". Keep the quotes.

You should see: a line like 1 file changed, 1 insertion(+). That means the save worked.

Command — show past saves, one line each

Command
git log --oneline

Word by word:

  • log — show the history of saves.
  • --oneline — the flag that squeezes each save onto one line.

You should see: one line per save, newest first, each starting with a short code and your message.

Command — list branches

Command
git branch

You should see: a list of branch names. The one with a * in front is the branch you are on now.

Command — make a new branch and move into it

Command
git checkout -b <name>

Word by word:

  • checkout — move to a different branch.
  • -b — the flag that means "make the branch first, because it does not exist yet".
  • <name> — placeholder. The new branch's name, for example git checkout -b fix-heading.

You should see: Switched to a new branch 'fix-heading'.

Command — merge a branch into the current one

Command
git merge <branch>

Word by word:

  • merge — combine another branch's changes into the branch you are on now.
  • <branch> — placeholder. The branch to bring in, for example git merge fix-heading.

You should see: a message saying the merge worked, or a message about a conflict (see the interview-pack lesson, question 4, for what a conflict is and how to fix it).

Command — send your saves to GitHub

Command
git push

Word by word:

  • push — send your saved versions up to GitHub.

You should see: lines about counting and writing objects, ending with something like main -> main. That means GitHub now has your saves.

Command — download and integrate the latest changes

Command
git pull

Word by word:

  • pull — fetch the latest changes from GitHub, then integrate them into your files.

"Fetch" means "download only, touch nothing". "Integrate" means "combine the downloaded changes with your files". pull does both steps at once. The combining is usually a merge. If your Git is set up to use a rebase instead, it replays your saves on top of the downloaded ones, one by one, so the history looks like a straight line. Rebase is a different way of combining; you do not need it as a beginner.

You should see: a message saying files were updated, or "Already up to date." if nothing changed.

Docker

Docker runs containers. An image is the packed box. A container is the image running. A port is a numbered door a program listens on — a browser knocks on a door number to reach a program.

Command — list running containers

Command
docker ps

Word by word:

  • docker — the program.
  • ps — list. Same idea as the Linux ps, but for containers.

You should see: a table with CONTAINER ID, IMAGE, STATUS, PORTS, and NAMES. The PORTS column is the important one: it shows which door on your machine leads to which door in the container.

Command — list all containers, including stopped ones

Command
docker ps -a

Word by word:

  • -a — the flag for "all". Without it you see only running containers. With it you also see stopped ones, which is how you find a container that died.

Command — list downloaded images

Command
docker images

You should see: a table of images on your machine, with REPOSITORY (the image name), TAG (the version label), and SIZE.

Command — prove Docker works

Command
docker run hello-world

Word by word:

  • run — start a container from an image.
  • hello-world — the image name. It is a tiny test image that prints a hello message and stops.

You should see: a message saying "Hello from Docker!" That means Docker works. If it says the image is not found and starts downloading it, that is normal the first time.

Command — run a website in the background on port 8080

Command
docker run -d -p 8080:80 --name web nginx

Word by word:

  • run — start a container.
  • -d — the flag for "detached". It means "run in the background and give me my terminal back". Without it, the container's output fills your terminal until you stop it.
  • -p 8080:80 — the flag for "publish a port". It connects two doors: 8080 is the door on YOUR machine, 80 is the door inside the container. Your browser knocks on http://localhost:8080 and Docker passes it to door 80 inside the container. The order is always outside:inside.
  • --name web — give this container the name web, so you can refer to it by name later instead of by its long ID.
  • nginx — the image name. nginx is a web server program, and also the name of the image that holds it. The program and the image share one name.

You should see: one long line of letters and numbers — the container ID. That means it started.

Then open http://localhost:8080 in your browser. "localhost" means "this machine". You should see the nginx welcome page.

Command — read a container's output

Command
docker logs <name>

Word by word:

  • logs — show what the container printed.
  • <name> — placeholder. The container's name or ID, for example docker logs web.

You should see: the lines the program inside printed. Errors are usually near the end. Read the first error line — that is the one thing to fix first.

Commands — stop, start, and remove a container

Command
docker stop <name>
docker start <name>
docker rm <name>

Word by word:

  • stop — tell the program inside to finish and halt. The container stays on your machine, stopped.
  • start — start a stopped container again.
  • rm — short for "remove". It deletes a stopped container. You cannot remove a running one — stop it first.

<name> is the container's name or ID in all three.

docker rm deletes things. Use it only on your own practice setup. Stopping is safe; removing deletes the container.

You should see: the container's name printed back. That means it worked.

Command — build an image from a Dockerfile

Command
docker build -t <name>:<tag> .

Word by word:

  • build — build an image.
  • -t — the flag for "tag". It names the finished image.
  • <name>:<tag> — placeholder. The name and the version label, joined by a colon, for example my-site:1.0. 1.0 is your version label. You choose it.
  • . — the dot means "this folder". It tells Docker: the recipe file (Dockerfile) and the files it needs are in this folder. This is called the build context.

You should see: lines scrolling past as Docker follows the recipe, ending with something like Successfully built or a line naming your image. If a step fails, the error names the step — fix that step in the Dockerfile.

Command — open a shell inside a running container

Command
docker exec -it <name> sh

Word by word:

  • exec — short for "execute". It means "run a command inside a container that is already running".
  • -i — the flag for "interactive". It keeps the input channel open so you can type.
  • -t — the flag for "terminal". It gives you a proper terminal screen inside the container.
  • <name> — placeholder. The container's name, for example docker exec -it web sh.
  • sh — the small shell program inside the container. A shell is the program that reads your typed commands.

You should see: a new prompt inside the container. You are now typing commands that run inside the box, not on your machine. Type exit to leave.

Command — share a folder from your machine into a container

Command
docker run -d -v ~/data:/data --name store ubuntu sleep 1000

Word by word:

  • -v ~/data:/data — the flag for "volume". It shares a folder: ~/data is a folder on YOUR machine (~ means your home folder), /data is where it appears inside the container. The two are joined by a colon. Files you put in ~/data appear inside the container at /data, and the other way round.
  • --name store — name this container store.
  • ubuntu — the image name. A plain Linux image.
  • sleep 1000 — the program to run inside: sleep does nothing for 1000 seconds. WHY: a container lives only as long as its main program runs. sleep 1000 keeps it alive for 1000 seconds so you have time to look inside it. Without it, the container would exit at once.

This is a bind mount: a folder on your machine shared into the container. Files in it live on your machine, not inside Docker's storage. That is different from a named volume, which is a folder Docker manages itself.

You should see: a container ID printed. Then docker exec -it store sh lets you look inside at /data.

Commands — start, list, and stop a Compose stack

Command
docker compose up -d
docker compose ps
docker compose down

Word by word:

  • compose — the Docker tool that starts several containers together from one file.
  • up — start everything the file describes.
  • -d — run in the background, as above.
  • ps — list the containers this Compose file started.
  • down — stop and remove the Compose containers. Your files stay; up starts them again later.

Why: some projects need three programs at once (for example a website, a database, and a monitor). Typing three long docker run commands is slow and easy to mistype. Compose reads one file and starts them all.

Which file? Compose looks for a file called docker-compose.yml (or compose.yml) in the folder you are standing in. If it says "no configuration file provided", you are in the wrong folder — cd into the folder that holds the file first. In this kit, each Phase 1 lab folder holds its own docker-compose.yml — for example phase1/kafka-lab/docker-compose.yml. Older Docker used docker-compose with a hyphen as a separate program; new Docker uses docker compose with a space. Both do the same job.

docker compose down deletes things. It stops and removes the Compose containers. Your files stay, but the containers are gone. Use it only on your own practice setup.

You should see for up -d: one line per service saying Started or Running. For ps: a table with NAME, IMAGE, STATUS. STATUS should say Up. For down: lines saying each container was removed.

Kubernetes (kubectl)

Kubernetes is a system that runs containers across several machines and keeps them running. A cluster is the group of machines Kubernetes manages. kubectl (say "cube-control") is the command tool you type to talk to a cluster.

Before any kubectl command works, a cluster must exist and kubectl must know where it is. In this kit the cluster comes from the kind lab below, or from the Kubernetes lab. If kubectl answers "connection refused", no cluster is running — start one first.

Command — list pods

Command
kubectl get pods

Word by word:

  • kubectl — the Kubernetes command tool.
  • get — show things.
  • pods — the things to show. A pod is the smallest thing Kubernetes runs, usually holding one container.

You should see: a table with NAME, READY, STATUS, and AGE. STATUS should say Running for a healthy pod. READY shows 1/1 when its one container is ready.

Command — list cluster machines

Command
kubectl get nodes

Word by word:

  • nodes — the machines in the cluster.

You should see: a table with NAME, STATUS, and AGE. STATUS should say Ready.

Command — list deployments

Command
kubectl get deployments

Word by word:

  • deployments — the things that keep a chosen number of copies of your app running. A deployment is a manager: you say "I want 2 copies", and it starts 2, replaces any that die, and handles updates.

You should see: a table with NAME, READY (like 2/2, meaning 2 of 2 copies are ready), and AGE.

Command — list services

Command
kubectl get services

Word by word:

  • services — the stable addresses inside the cluster for pods that come and go. A service is a fixed address that always points at the current healthy copies of your app, even when individual pods die and are replaced.

You should see: a table with NAME, TYPE, and PORT(S).

Command — open a service in your browser

Command
kubectl port-forward service/<name> 8080:80

Word by word:

  • port-forward — make a temporary tunnel from your machine into the cluster.
  • service/<name> — which service to tunnel to. The word service says what kind of thing it is, then a slash, then the service's name, for example service/my-site.
  • 8080:80 — the doors: 8080 on your machine, 80 in the cluster. Same outside:inside order as Docker's -p.

You should see: a line saying Forwarding from 127.0.0.1:8080 -> 80. Then open http://localhost:8080. Keep this command running — press Ctrl+C to stop the tunnel when you are done. This opens the service only on your machine; it does not put it on the internet.

Command — show details about one pod

Command
kubectl describe pod <name>

Word by word:

  • describe — show full details.
  • pod <name> — the pod to describe, for example kubectl describe pod my-site-abc-123.

You should see: a long block of details. The part that matters most is Events: at the bottom — a short history of what happened to the pod, newest last. If a pod cannot start, the reason is usually in the last few Events lines.

Command — read a pod's logs

Command
kubectl logs <pod>

Word by word:

  • logs — show what the program inside the pod printed.
  • <pod> — placeholder. The pod's name.

You should see: the program's printed lines. Same rule as Docker: read the first error line.

Command — read the crashed run's logs after a restart

Command
kubectl logs <pod> --previous

Word by word:

  • --previous — the flag that means "show the logs of the run BEFORE this one".

Why and when: when a pod crashes, Kubernetes starts it again. The new run's logs start fresh — the error that killed the first run is gone from the current logs. --previous shows the dead run's logs.

Use it when: kubectl get pods shows a pod with RESTARTS more than 0, and the current logs look clean. That combination means the crash already happened and restarted. Example: the pod shows RESTARTS 3, the normal logs show only startup lines, so you run kubectl logs <pod> --previous and find the real error — for example a wrong image name — in the old run's output.

Commands — create and remove things from a file

Command
kubectl apply -f <file.yaml>
kubectl delete -f <file.yaml>

Word by word:

  • apply — create the things the file describes, or update them if they already exist.
  • delete — remove the things the file describes.
  • -f — the flag for "file". It says the next word is a file name.
  • <file.yaml> — placeholder. The settings file, for example deployment.yaml.

kubectl delete -f deletes things. It removes what the file describes. Use it only on your own practice setup.

You should see for apply: one line per thing created, like deployment.apps/my-site created. For delete: deployment.apps/my-site deleted.

kind (local Kubernetes)

kind is a tool that runs a whole Kubernetes cluster inside Docker on your own machine. "kind" stands for "Kubernetes in Docker". Why: you need a cluster to practise kubectl, and kind gives you one without any cloud account or bill.

Command — start a local cluster

Command
kind create cluster --name devops-practice

Word by word:

  • create cluster — make a new cluster.
  • --name devops-practice — call it devops-practice. You choose the name; the kit uses this one so every later command matches.

You should see: lines about creating nodes, ending with something like Cluster creation complete. Then kubectl get nodes should list one node with STATUS Ready.

Command — copy a local image into the cluster

Command
kind load docker-image my-site:1.0 --name devops-practice

Word by word:

  • load docker-image — copy an image from Docker on your machine into the cluster.
  • my-site:1.0 — the image to copy.
  • --name devops-practice — which cluster to load it into.

Why: kind runs the cluster inside Docker containers. Your machine's Docker images are outside that cluster, so the cluster cannot see them. You have to load the image in first. If you skip this step, the pod fails with ImagePullBackOff — Kubernetes tried to download an image that does not exist anywhere it can reach.

You should see: a line saying the image was loaded.

Command — remove the cluster

Command
kind delete cluster --name devops-practice

Word by word:

  • delete cluster — remove the whole cluster.
  • --name devops-practice — which cluster.

kind delete cluster deletes things. It removes the whole practice cluster. Use it only on your own practice setup.

You should see: a line saying the cluster was deleted. This removes everything in that practice cluster. It does not touch your files.

Terraform

Terraform is a tool that creates infrastructure from files. Infrastructure means the things your app runs on: containers, networks, machines. Infrastructure as code means writing down what you want in files, and letting a tool create it, instead of clicking around by hand.

Terraform keeps a file called state. State is Terraform's notebook: it maps each thing in your files to the real thing it created, so it knows what exists and what to change next. State can hold private values, so it must never go into a public repository.

Command — prepare a folder for Terraform

Command
terraform init

Word by word:

  • init — short for "initialise". It downloads the provider your files ask for (a provider is the plug-in that lets Terraform talk to Docker, or to a cloud service) and makes a .terraform/ folder and a .terraform.lock.hcl file. The lock file records the exact provider version, so the next run uses the same one.

You should see: lines about downloading, ending with Terraform has been successfully initialized!

Run init once per folder, and again if you change which provider your files ask for.

Command — show what Terraform would change

Command
terraform plan

Word by word:

  • plan — work out what would change, and show it, without changing anything.

You should see: a list of things to add, change, or destroy. If nothing would change, it says No changes. Your infrastructure matches the configuration. That line is the proof that the last apply worked and nothing drifted.

Why run it: it is the safe preview. You read the plan before you apply, so you never create something by surprise.

Command — create or change the infrastructure

Command
terraform apply

Word by word:

  • apply — do what the plan says: create or change things for real.

You should see: the plan printed first, then a question asking you to confirm. Type yes and press Enter. Then lines about creating things, ending with something like Apply complete! Resources: 1 added, 0 changed, 0 destroyed. The three numbers are the proof: how many things were added, changed, and destroyed.

Command — remove everything Terraform created (DANGEROUS)

Command
terraform destroy

Word by word:

  • destroy — remove everything the active configuration and state manage.

What it deletes, in plain words: every container, network, and other thing Terraform created from the files in the folder you are standing in. It deletes only what Terraform's state notebook says it created. It does not delete your files.

Before you run it, do all three checks:

  1. Check you are in the right folder: run pwd. The folder shown must be your practice folder.
  2. Check the workspace and state: run terraform plan and read it. A workspace is a named separate copy of state in the same folder; the default one is called default. If you ever made another workspace, make sure you are in the right one.
  3. Read the destruction plan first: run terraform plan -destroy. This shows exactly what would be deleted, without deleting anything. Read every line.

Only then run terraform destroy, and type yes when it asks.

Run it only on your own disposable practice setup. Never on anything shared or real, and never without the plan check above. There is no undo.

You should see: lines about destroying things, ending with Destroy complete! Resources: 1 destroyed. If it asks for confirmation and you are not sure, type no.

Prometheus and Grafana (concepts, not commands)

There are no commands to type in this section. It is two ideas to learn.

  • Prometheus collects numbers (called metrics) from your apps. A metric is a number measured over time, like CPU use or how many requests arrived. Prometheus visits an address every few seconds and writes the numbers down. Each visit is called a scrape. Each address it visits is called a target.
  • Grafana turns those numbers into charts you can look at.

The two things to check first when something looks wrong: is the app up, and is it slow? "Up" means it answers. "Slow" means it answers late.

You will use both for real in Portfolio Project 3, where the portfolio-projects lesson walks through every click.

Kafka (Phase 1 — run inside the container)

Kafka is a message line. Programs put messages into a named line called a topic, and other programs take messages out of the line and do the work. Messages wait safely in the line if the reader is slow.

Why these commands run inside the container: Kafka tells other programs to come back to the container's own name. From your own terminal, that name does not resolve. So every Kafka command below starts with docker exec kafka-a ..., which means "run this command inside the container named kafka-a".

The container names kafka-a and kafka-b come from the Phase 1 Kafka lab, which starts two Kafka clusters on one machine. If you have not done that lab, these containers do not exist yet and the commands will fail with "no such container".

Command — list topics on cluster A

Command
docker exec kafka-a /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --list

Word by word:

  • docker exec kafka-a — run the next command inside the container named kafka-a.
  • /opt/kafka/bin/kafka-topics.sh — the Kafka program that manages topics. It lives at that path inside the container.
  • --bootstrap-server localhost:9092 — the address of the Kafka server to talk to. A bootstrap server is the first address a client contacts to find the cluster. localhost:9092 means "this machine, door 9092". Inside the container, "this machine" is the container itself.
  • --list — the action: list the topics.

You should see: one topic name per line, for example orders. If nothing prints, no topics exist yet.

Command — make a topic called orders

Command
docker exec kafka-a /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --partitions 1 --replication-factor 1

Word by word:

  • --create — the action: make a new topic.
  • --topic orders — name the topic orders.
  • --partitions 1 — split the topic into 1 part. A partition is a slice of a topic. One slice is enough for practice.
  • --replication-factor 1 — keep 1 copy of each message. "Replication" means keeping extra copies. One copy is enough for practice.

You should see: Created topic orders.

Command — send messages (type lines, Ctrl+C to stop)

Command
docker exec -it kafka-a /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders

Word by word:

  • -it — interactive terminal, as in the Docker section: it lets you type.
  • kafka-console-producer.sh — the program that sends messages. A producer is a program that puts messages into a topic.
  • --topic orders — send into the topic named orders.

You should see: a > prompt. Type a line and press Enter — that line is now a message in the topic. Press Ctrl+C to stop. Ctrl+C means "stop the program I am typing into".

Command — read messages from the start

Command
docker exec kafka-a /opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --from-beginning

Word by word:

  • kafka-console-consumer.sh — the program that reads messages. A consumer is a program that takes messages out of a topic.
  • --from-beginning — start from the oldest message, not only new ones.

You should see: every message in the topic, one per line, in order. Press Ctrl+C to stop. If nothing prints, no messages were sent yet, or you are looking at the wrong cluster — check the topic list on the right cluster.

PostgreSQL (Phase 1 — run inside the container)

PostgreSQL is a database: a program that stores rows in tables and answers questions about them. The Phase 1 lab runs two copies: a primary that takes writes (new and changed rows) and a replica (also called a standby) that follows the primary by reading its change log and takes reads only. The containers are named pg-primary and pg-replica.

psql is the command tool for talking to PostgreSQL. -U learner means "log in as the user named learner". -d practice means "use the database named practice". -c "..." means "run this one question (a SQL query) and print the answer".

Command — read rows from the primary

Command
docker exec pg-primary psql -U learner -d practice -c "SELECT * FROM orders ORDER BY id;"

Word by word:

  • docker exec pg-primary — run inside the container named pg-primary.
  • psql -U learner -d practice — open the database tool as user learner, database practice.
  • -c "SELECT * FROM orders ORDER BY id;" — run this question: "show every column (*) from the table named orders, sorted by id". SQL is the language databases use for questions. SELECT means "show". FROM orders means "from the table orders". ORDER BY id means "sort by the id column".

You should see: a table of rows. If the table is empty, you see only the column names. That means no orders were saved yet.

Command — check whether this copy is a standby

Command
docker exec pg-replica psql -U learner -d practice -c "SELECT pg_is_in_recovery();"

Word by word:

  • pg_is_in_recovery() — a built-in question that asks "am I a standby following someone else?" The answer is t (true) or f (false).

You should see: t on the replica (it IS a standby — correct), f on the primary (it is NOT a standby — correct). If the replica shows f, something is wrong: it is no longer following.

Command — promote the standby to primary

Command
docker exec pg-replica psql -U learner -d practice -c "SELECT pg_promote();"

Word by word:

  • pg_promote() — a built-in command that says "stop following and become the primary".

Why: when the primary dies, you promote the standby so writes have somewhere to go. After promoting, check pg_is_in_recovery() again — it should now show f. The old primary cannot just rejoin afterwards; it must be rebuilt from the new primary.

Command — open an interactive psql shell

Command
docker exec pg-primary psql -U learner -d practice

Without -c, psql opens a prompt where you type questions one by one. Type \q and press Enter to leave.

A standby refuses writes — that is correct, not a bug. If you try to add a row on the replica, PostgreSQL answers "cannot execute INSERT in a read-only transaction". The replica takes reads only. Write on the primary, or promote the replica first.

Patroni (Phase 1)

Patroni is a watcher program. It watches the databases and promotes the standby by itself within seconds when the leader stops, so nobody has to be awake at night to run the command. A leader is the database currently taking writes.

Patroni answers questions on a small web page. Node 1 answers on door 8008, node 2 on door 8009.

curl is a program that asks a web address for its page and prints the answer. curl http://localhost:8008/cluster means "ask the program on this machine, door 8008, for the page called /cluster".

Command — show the cluster: who is leader, who is replica

Command
curl http://localhost:8008/cluster

You should see: a block of text naming each member, with one marked leader and the others marked replica. The leader is the one taking writes.

Command — show the leader only

Command
curl http://localhost:8008/leader

You should see: a short answer naming the leader only.

If curl answers "connection refused", Patroni is not running on that door — check the lab is up.

Redis (Phase 1 — run inside the container)

Redis is a fast memory store. It keeps small answers in memory so reads are very fast: saved values, counters, short-lived codes. It is not the main record book — memory is small, and the real records belong in the database, where they are safe even when the power goes out.

redis-cli is the command tool for talking to Redis. The containers are named redis-a (the main store) and redis-b (the copy).

Command — check Redis answers

Command
docker exec redis-a redis-cli ping

Word by word:

  • ping — the Redis question "are you there?" It is a test, like knocking on a door.

You should see: PONG. That one word means Redis is up and answering. Anything else means it is not.

Command — save a value

Command
docker exec redis-a redis-cli SET user:101 Asha

Word by word:

  • SET — save a value.
  • user:101 — the key (the name under which the value is stored). Keys often look like type:number.
  • Asha — the value to save.

You should see: OK.

Command — read it back

Command
docker exec redis-a redis-cli GET user:101

Word by word:

  • GET — read the value stored under this key.

You should see: Asha. If you see (nil), the key does not exist — either it was never saved, or it expired.

Command — save a value that deletes itself after 60 seconds

Command
docker exec redis-a redis-cli SETEX login-code:101 60 482913

Word by word:

  • SETEX — "set with an expiry". Save a value that deletes itself after a number of seconds.
  • login-code:101 — the key.
  • 60 — the number of seconds before it deletes itself.
  • 482913 — the value. Here it is a pretend login code. It is fake, for practice only.

You should see: OK.

Command — seconds left before it deletes itself

Command
docker exec redis-a redis-cli TTL login-code:101

Word by word:

  • TTL — short for "time to live". It asks "how many seconds are left before this key deletes itself?"

You should see: a number, for example 42. It counts down. When it reaches -2, the key is gone.

Command — add 1 to a counter

Command
docker exec redis-a redis-cli INCR orders:count

Word by word:

  • INCR — short for "increment". Add 1 to the number stored under this key.

You should see: the new number, for example 1 the first time, 2 the second time. If the key did not exist, Redis starts it at 0 and then adds 1.

Command — check the copy is following the main store

Command
docker exec redis-b redis-cli INFO replication

Word by word:

  • INFO replication — show information about copying. Replication means keeping a second copy up to date by copying every change from the main one.

You should see: a block of lines. The lines that matter say role:slave (this copy follows the main store) and master_link_status:up (the link to the main store is working). If it says down, the copy is not following. role:slave is Redis's older word for "the copy that follows"; newer Redis calls it a replica.

A one-way copy takes reads only. If you try to save on redis-b, Redis answers with a READONLY error. That is correct, not a bug.

Moto and aws (Phase 1 — object store)

An object store keeps whole files by name — pictures, documents, uploads. You ask a store for a file by name. A database keeps rows in tables and answers questions about them. Files go in the store; rows go in the database.

Moto is a pretend object store that runs on your machine and acts like the real S3 store, so you can practise without an account or a bill. The aws tool is the command tool for talking to object stores. The Phase 1 lab runs two Moto stores (moto-a and moto-b) and a container named awscli that holds the aws tool.

Every command below has three layers. Read it left to right:

  1. docker compose exec awscli — "run the next command inside the container named awscli, which belongs to this Compose stack".
  2. aws — the command tool.
  3. --endpoint-url http://moto-a:5000 — "talk to the Moto store named moto-a on door 5000, not the real cloud". moto-a works as an address because Compose lets containers reach each other by service name.

Command — make a bucket called incoming

Command
docker compose exec awscli aws --endpoint-url http://moto-a:5000 s3 mb s3://incoming

Word by word, after the three layers above:

  • s3 — the object-store part of the aws tool.
  • mb — short for "make bucket". A bucket is a named box inside the store that holds files.
  • s3://incoming — the bucket's address. s3:// means "in the object store", and incoming is the bucket's name.

You should see: make_bucket: incoming.

Command — upload a file

Command
docker compose exec awscli aws --endpoint-url http://moto-a:5000 s3 cp /files/receipt-001.txt s3://incoming/

Word by word:

  • cp — short for "copy".
  • /files/receipt-001.txt — the file on your machine to upload. It lives in the files folder that the Phase 1 object-store lab shares into the awscli container. The lab folder holds files/receipt-001.txt and files/receipt-002.txt on your machine; inside the container the shared folder appears at /files. If the file is not there, the lab did not start correctly.
  • s3://incoming/ — the destination: into the bucket named incoming. The / at the end means "into this bucket".

You should see: upload: ./receipt-001.txt to s3://incoming/receipt-001.txt.

Command — list files in the bucket

Command
docker compose exec awscli aws --endpoint-url http://moto-a:5000 s3 ls s3://incoming/

Word by word:

  • ls — list.

You should see: one line per file, with a date, a size, and the file name, for example receipt-001.txt.

Command — print a file's contents from the second store

Command
docker compose exec awscli aws --endpoint-url http://moto-b:5000 s3 cp s3://incoming/receipt-001.txt -

Word by word:

  • --endpoint-url http://moto-b:5000 — this time talk to the SECOND store, moto-b. That is the point: the file was uploaded to the first store, and the lab's mirror copied it to the second store by itself.
  • s3 cp s3://incoming/receipt-001.txt - — copy the file from the bucket, and print it to the screen. The - at the end means "to the screen, not to a file".

You should see: the file's words printed. If it says the file does not exist, wait a minute — the mirror copies on a delay — then try again.

NGINX load balancer (Phase 1)

A load balancer stands in front of copies of your app and sends each visitor to a different copy, so no single copy gets all the work. If a copy dies, the balancer skips it and uses the ones still alive — the site stays up. NGINX is the program doing the balancing here. A backend is one copy of your app behind the balancer.

Command — ask the load balancer for the page

Command
curl http://localhost:8080/

Word by word:

  • curl — ask a web address for its page and print the answer.
  • http://localhost:8080/ — the load balancer's address on your machine, door 8080.

You should see: a small web page. Run it again — a different backend answers each time. That is the proof the balancer is sharing the work: the page says which backend answered, and the name changes between runs.

Command — read what the load balancer saw

Command
docker compose logs lb

Word by word:

  • docker compose logs — show the printed output of a container in this Compose stack.
  • lb — the service name of the load balancer in the lab's Compose file.

You should see: one line per request the balancer handled. If the balancer answers the same backend every time, check docker compose ps — a dead backend is skipped by the balancer's guard, which is correct behaviour, not a bug.

Troubleshooting index — error, then where to look

This is the lesson's own index, rewritten so each entry says what happened, what it means, and where the fix lives. "Lab" means the break-and-fix labs lesson; "Phase 1" means the single-topic labs.

  • "image not found" / container never starts → Lab 1 in the break-and-fix labs. The command that produced it is docker run with a wrong image name. Read Docker's error, check the image name and tag. A wrong letter in the name is the usual cause.
  • Container starts, then dies at once → Lab 2. The command that produced it is docker run with a main program that finishes instantly. The main program exited. A container lives only as long as its main program runs — run the real foreground program, not a program that finishes instantly.
  • Pipeline fails on a missing test file → Lab 3. The command that produced it is the pipeline run after git push. Write the real test. Do not bypass it.
  • Git merge conflict → Lab 4. The command that produced it is git merge <branch>. Read the markers, pick the right lines, delete the markers, stage the file, commit to finish the merge.
  • Browser shows nothing but the container runs → Lab 5. The command that produced it is docker run without a -p mapping. Check the PORTS column in docker ps. The -p mapping is the door; logs alone do not prove the browser can reach the app.
  • Docker build "file not found" → Lab 6. The command that produced it is docker build -t <name>:<tag> .. Check the build context (the folder after docker build) and .dockerignore (the file that tells Docker which files to leave out of the build).
  • Pod crashes, bad image → Kubernetes lab, Step 5. The command that produced it is kubectl apply -f <file.yaml> with a wrong image name. Describe the pod, fix the Deployment, check rollout status.
  • Monitoring target DOWN → Portfolio Project 3. The command that produced it is the Prometheus Targets check. Check docker compose ps, then the service logs, then the Prometheus Targets error line, in that order.
  • Kafka topic missing or consumer shows nothing → Phase 1 Kafka lab. The commands that produced it are the kafka-topics.sh --list and kafka-console-consumer.sh commands above. Check the topic list on the right cluster, and remember Kafka commands run with docker exec inside the container, not from your own terminal.
  • PostgreSQL replica shows 0 rows → Phase 1 PostgreSQL lab. The command that produced it is the SELECT * FROM orders ORDER BY id; read on the replica. Wait 10 seconds and try again, then check SELECT pg_is_in_recovery(); shows t on the replica.
  • "cannot execute INSERT in a read-only transaction" on a replica → correct, not a bug. The command that produced it is an INSERT run on pg-replica. A standby takes reads only. Write on the primary, or promote the replica first.
  • Redis READONLY error on the copy → correct, not a bug. The command that produced it is a SET run on redis-b. A one-way copy takes reads only.
  • Moto file missing from the second store → Phase 1 object-store lab. The command that produced it is the s3 cp s3://incoming/receipt-001.txt - read from moto-b. Wait a minute, then check docker compose logs mirror for the error line.
  • Load balancer answers the same backend every time → Phase 1 load-balancer lab. The command that produced it is curl http://localhost:8080/ run several times. Check docker compose ps — a dead backend is skipped by the balancer's guard, which is correct behaviour.

Which commands are safe to practise, and which are not

Most commands in this lesson only read things: ps, logs, get, status, plan, ls, cat. Reading is safe.

These commands change or delete things. Use them only on your own practice setup, never on anything shared or real:

  • docker rm — deletes a container.
  • docker compose down — stops and removes Compose containers (your files stay).
  • kubectl delete -f — removes what the file describes.
  • kind delete cluster — removes a whole practice cluster.
  • terraform destroy — removes everything Terraform created. Read the destruction plan first. There is no undo.

Advanced reference — Severity, incidents, rollback, alerting, Terraform state

This section is a reference, like the rest of this file: short entries, no long explanations. The plain-words explanations live in the break-and-fix labs' Advanced section and the error decoder's Advanced section — this section is the quick-lookup version of the same material, plus Terraform state commands and a Prometheus alerting rule.

Severity — the four grades

  • S1 — everything is down, or money or data is being lost. Drop everything. Roll back first.
  • S2 — a big part is broken, many users hurt, the main job still works for most. Urgent, one owner.
  • S3 — a small part is broken, and a workaround exists. Fix in working hours.
  • S4 — cosmetic. Write it down, fix it with the next change.
  • Three questions set the grade: who is hurt, can they do the main job another way, is money or data being lost right now.

Incident timeline — copy this template

Command
Incident:
Started at (first alert or report):
What users see (one line):
Severity (S1-S4):
Checks (time — command — what it showed):
Changes (time — what changed):
Recovered at (and how you know — a number, not "looks fine"):
Still unknown:

Rollback — the commands

  • git revert <commit> — undo a commit by adding a new commit that reverses it. Safe on shared branches. Never git reset --hard on a branch others already have.
  • kubectl rollout history deployment/<name> — list the versions you can go back to.
  • kubectl rollout undo deployment/<name> — go back to the previous version.
  • kubectl rollout undo deployment/<name> --to-revision=<n> — go back to one exact version from the history list.
  • Docker: re-run the previous image tag (my-site:1.0). A tag called latest cannot be rolled back to — it moves.

Alerting — the Prometheus rule shape

Command
groups:
  - name: practice
    rules:
      - alert: TargetDown
        expr: up == 0
        for: 5m
  • groups: — the list of rule groups. name: practice names this group.
  • alert: TargetDown — the alert's name. It fires when the expression stays true.
  • expr: up == 0 — the expression. up is the query from the portfolio lesson: 1 means the target answered, 0 means it did not. So this fires when a target stops answering.
  • for: 5m — it must stay wrong for 5 minutes before it fires, so a 10-second blip does not wake anyone.
  • Every alert needs a first step written with it: which runbook entry to open, or which rollback to run. An alert with no first step wastes the first ten minutes.

Terraform — state commands

  • terraform state list — list everything in the state file (the notebook mapping your files to real things).
  • terraform state show <address> — show one thing's details from state, for example terraform state show docker_container.web.
  • terraform state pull — print the whole state file as JSON (for scripts, not for reading by eye).
  • terraform state mv <old> <new> — rename a thing in state when you rename it in your files, so Terraform does not delete it and recreate it.
  • terraform state rm <address> — remove a thing from state when it was deleted outside Terraform. This does not delete the real thing — it only stops Terraform tracking it.
  • Never edit a .tfstate file by hand. The format is internal and a wrong edit corrupts it. Always use terraform state commands.
  • terraform fmt -check — check your files are formatted correctly, without changing them.
  • terraform validate — check your files are valid, without creating anything.
  • terraform test — run the .tftest.hcl test files (see the portfolio lesson's Advanced section).

Logs — beyond this file

  • journalctl -u docker — read Docker's own log on a Linux machine.
  • kubectl logs <pod> --previous — the dead run's logs (already in this file above).
  • Central log tools to know by name: Splunk, Datadog, CloudWatch Logs, Grafana Loki. The habit that transfers: fix the FIRST error in the chain, and follow one request with a correlation ID (one code stamped on a request through every service).

Quick check — try it yourself

Question: In the terminal, type: df -h — what percentage of the main disk (/) is used?

Open the practice terminal to test this →

Show answer

Any percentage on the / line — yours will differ by machine. On the example machine it was 44% (/dev/sda1 20G 8.5G 11G 44% /).