← All chapters

Chapter 6

Chapter 6: The Cleanup Crew

Max learns that even robots need to take out the trash.

Three months had passed since Max started this journey. The Minecraft server was humming along. His friends played every evening. Jake had rebuilt his castle twice (each time bigger). Emma had constructed an entire underground city. The CI pipeline caught Max's mistakes before they caused problems.

Everything was working.

Then one day, Max's laptop started running slow. Really slow. He texted me in a panic.

😕
Max

My computer is crawling! And I keep getting warnings about disk space. But I only have one server running! Where did all my storage go?

I had a pretty good guess.

"Open a terminal," I said. "Let's see what Docker's been hoarding."

Where Did All The Space Go?

$Check Docker's disk usage
Max

Twenty-three images?! I only meant to download like three!

"Remember all those times you experimented? Tried different images? Pulled new versions? Docker keeps everything unless you tell it not to."

I pointed at the screen. "See those numbers? You have 4.8 gigabytes of images, but only 1 is actually being used. The rest are taking up space for no reason. Same with containers—17 exist, but only 1 is running."

"Docker is like a digital packrat. It never throws anything away on its own."

💡 CONCEPT

Docker's Hoarding Problem

Docker doesn't automatically delete things:

  • Images stay even after you stop using them
  • Stopped containers persist for debugging/logs
  • Volumes survive container deletion (by design!)
  • Build cache accumulates over time

This is usually good—you don't want surprise data loss. But it means you need to clean up periodically, just like taking out the trash.

Understanding What Piles Up

"Let's look at what's actually there," I said.

$See all containers (including stopped)
Max

Oh. Those are all my experiments. I thought they just... went away when I stopped them.

"Nope. docker stop stops a container. docker rm removes it. Without that second step, they just sit there, taking up space and cluttering your list."

"Same with images. Let's look."

$See all images
terminal output(text)

"See those <none> entries? Those are called 'dangling images'—leftover layers from builds that didn't complete cleanly, or old versions that got replaced. They're safe to remove."

"And those multiple alpine versions? You probably only need one."

Cleaning Up Containers

"Let's start cleaning. The safest place to begin is stopped containers."

$Remove all stopped containers
terminal output(text)
🤔
Max

It asked for confirmation. That's nice.

"Docker's prune commands always confirm first. It's a safety net. You can skip the confirmation with -f for scripting, but be careful with that."

Cleaning Up Images

$Remove dangling images
terminal output(text)

"That removed the <none> images—the ones without names. But what about all those old alpine versions you don't need anymore?"

$Remove ALL unused images
⚠️Think Before You Prune

docker image prune -a removes ALL images not used by running containers. Next time you start something, Docker will have to re-download the images.

This is fine for cleanup, but if you're on slow internet or have data caps, you might want to be more selective.

🧐
Max

What if I want to remove just one specific image?

$Remove a specific image

"rmi means 'remove image.' You can use the image name or the ID. Docker will complain if the image is still being used by a container—that's another safety net."

The Nuclear Option

"Sometimes you just want to start fresh. There's a command for that."

$Clean everything at once
terminal output(text)
Max

1.2 gigabytes! That's so much space!

"Notice what it doesn't touch: volumes. Docker protects your data by default. Your Minecraft world is safe."

"If you really want to remove unused volumes too—which you almost never do—you can add --volumes. But that's genuinely dangerous."

$Nuclear option INCLUDING volumes (DANGER!)
⚠️Volumes = Your Data

--volumes will delete any volume not attached to a running container. This includes your Minecraft world if the server happens to be stopped.

Never run this casually. Make backups first. Know exactly what you're deleting.

Volume Management

"Let's talk about volumes specifically. They're the most important thing to be careful with."

$List all volumes
terminal output(text)
😕
Max

Some of these I don't even remember making.

"That happens. Every time you use -v with a new volume name, Docker creates it. The volume persists even after the container is gone."

"Let's see what's actually being used."

$Check which volumes are in use

"That's a bit arcane, but it shows which volumes are mounted to containers. Anything not in that list is probably safe to remove—but check first!"

"To remove a specific volume:"

$Remove a specific volume
$Remove all unused volumes (careful!)

"The prune command will only remove volumes not attached to any container—running or stopped. But if you've removed the container, the volume is fair game. Be sure you don't need that data."

Setting Up Automatic Cleanup

"Cleaning up manually works, but it's easy to forget. Real operators automate this."

cleanup.sh(bash)
$Make it executable

"Now let's schedule it to run automatically. We'll use cron—the classic Unix scheduler."

$Open your crontab
Add this line to crontab(text)
💡Cron Syntax
┌───────────── minute (0-59)
│ ┌─────────── hour (0-23)
│ │ ┌───────── day of month (1-31)
│ │ │ ┌─────── month (1-12)
│ │ │ │ ┌───── day of week (0-6, Sunday=0)
│ │ │ │ │
0 3 * * 0  command

This says: "Run at minute 0, hour 3, any day of month, any month, on Sunday."

Max

So now my computer cleans up after itself. That's pretty cool.

A Simple Health Check

"One more thing," I said. "Good operators don't just clean up—they monitor. A quick health check script can catch problems before they become emergencies."

health-check.sh(bash)

Max ran the script. Everything looked healthy.

"You could schedule this to run daily and email you the results," I said. "Or log to a file and check it when you remember. The point is: know the state of your system."

The Journey So Far

I leaned back in my chair. Max had come a long way.

"You know what you've learned over these past few months?"

🤔
Max

How to run a Minecraft server?

"You've learned DevOps."

I let that sink in.

"Think about it. You started with a simple goal: run a game server. Along the way, you learned:

  • Containers: How to package and run software reliably
  • Volumes: How to persist data that matters
  • Compose: How to orchestrate multiple services
  • Scripts: How to automate repetitive tasks
  • Git: How to track changes and undo mistakes
  • CI/CD: How to make robots check your work
  • Maintenance: How to keep systems healthy long-term

That's not just 'running a Minecraft server.' That's operating infrastructure. Real companies pay people good money to do what you just learned."

Max

Wait... I actually know DevOps now?

"You know the foundations. There's always more to learn—networking, security, scaling, monitoring at scale—but you've got the mindset. Automate the boring stuff. Save your work. Keep things tidy. Experiment without fear."

"Those principles work whether you're running a game server or a billion-dollar cloud platform. The scale changes; the thinking doesn't."

What's Next?

"So what now?" Max asked. "Is that it?"

"That's Volume 1. Your server is running, your friends are playing, and you're not afraid of the terminal anymore. But there's more."

💡Coming in Volume 2: The Bot
  • Discord bots: Build an assistant that watches your server
  • Python: A new language, a new superpower
  • Minecraft integration: Know who's online without logging in
  • Personality: Give your bot some character
  • Safety: Keeping your server (and your friends) safe

"For now, though? You've got everything you need. Your server works. Your automation handles the boring stuff. Your Git history protects your work. Your CI catches your mistakes."

"Go play Minecraft with your friends. You've earned it."

Max

Thanks for teaching me all this. It was... actually kind of fun?

"That's the secret," I said. "Learning's always more fun when you're building something you care about. The Minecraft server was never really the point—it was the excuse."

Max grinned and headed for his laptop. A few seconds later, I heard the familiar loading music.

Some things never change.

🧠 MEMORY

Docker Maintenance Checklist

Weekly Cleanup

docker container prune -f  # Remove stopped containers
docker image prune -f      # Remove dangling images
docker network prune -f    # Remove unused networks

Monthly Deep Clean

docker system prune -a     # Remove all unused data
# Check volumes manually before pruning!

Health Check

docker system df           # Disk usage
docker ps                  # Running containers
docker stats               # Resource usage

Backup Before Major Changes

docker run --rm -v mydata:/data -v $(pwd):/backup \
  alpine tar cvf /backup/mydata-backup.tar /data

Cron Schedule (Weekly Cleanup)

0 3 * * 0 docker system prune -f >> /var/log/docker-cleanup.log 2>&1

When Something's Wrong

  1. Check if container is running: docker ps
  2. Check logs: docker logs <name>
  3. Check resources: docker stats
  4. Check disk: docker system df
  5. Restart if needed: docker restart <name>
Type a command below or scroll through content...
$
Vol
0/4
Ch
0/1
Cmd
0
Egg
0/7
LVL 1
Newbie
0 XP