Docker is amazing. It’s like magic Tupperware for your code. But if you aren't careful, that Tupperware piles up until your hard drive is screaming for mercy and your computer starts acting like a sullen teenager.
Here is your survival guide to checking disk space, running apps, and performing the digital equivalent of a "Marie Kondo" cleanup.
1. The Reality Check
Before we start cleaning, we need to know how bad the damage is.
Check Disk Space
df -h
The Vibe: This is like stepping on the scale after the holidays. What it does:
df: stands for Disk Free.-h: stands for Human-readable. Because nobody knows what4194304 blocksmeans, but everyone understands40GB.Use when: Your computer says "Disk Full" and you want to see if Docker is the culprit (spoiler: it usually is).
2. The Daily Routine
The stuff you do when you're actually working and not just panicking about space.
List Local Images
docker images
The Vibe: Opening your closet and staring at all the shirts you own. What it does: Shows you every "blueprint" (image) you have downloaded or built.
Run a Container
docker run -d --name api -p 3000:3000 squarestory/inspecto_api:latest
The Vibe: Taking a frozen pizza (Image) and actually cooking it (Container). Breakdown:
-d(Detached): Runs in the background. If you don't use this, the container attaches to your terminal like a clingy toddler and dies if you close the window.--name api: Gives it a cute nickname so you don't have to refer to it by a random ID likea1b2c3d4.-p 3000:3000: Port mapping. It punches a hole in the container wall so you can access it from your browser.
Ship It (Push to Docker Hub)
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
docker push squarestory/inspecto_api:latest
The Vibe: Packing up your creation and mailing it to the warehouse. What it does:
The first line logs you in securely (so you aren't typing your password where everyone can see it).
push: Uploads your image to the internet so your server (or your friend) can download it.
3. Light Cleaning (Tidying Up)
Use these when you want to free up space but are afraid of deleting something important.
Remove "Dangling" Images
docker image prune
# OR slightly more aggressive:
docker image prune -f
The Vibe: Throwing away the trash. What it does: Removes images that have no name and no tag (often called <none>). These are usually leftover junk from when you rebuilt an image 15 times in one hour.
-f: Force. Don't ask me "Are you sure?" just do it.
4. Deep Cleaning (The "Spring Clean")
Use this when you need serious space back.
The "Nuke It" Command
docker system prune -a -f --volumes
The Vibe: The Deep Clean. You are scrubbing the grout with a toothbrush. What it does: This deletes everything that isn't currently being used by a running container.
system prune: The main cleanup command.-a(All): Removes unused images, not just dangling ones. If you aren't using it right now, it goes in the bin.--volumes: Removes unused storage volumes. Warning: This deletes database data if the database isn't running!-f: Force. No mercy.
5. The "Scorched Earth" Protocol
Sometimes, things are so broken that you just want to burn it all down and start over. These commands are for those moments.
Stop Everything
docker stop $(docker ps -q)
The Vibe: Yelling "EVERYBODY FREEZE!" in a crowded room. How it works:
docker ps -q: Lists only the IDs (-qfor quiet) of running containers.$(): Passes those IDs to thedocker stopcommand.
Delete Every Container
docker rm $(docker ps -aq)
The Vibe: Evicting everyone from the building. How it works:
docker ps -aq: Lists all container IDs (-a), even the stopped ones.docker rm: Removes them.
Delete Every Image
docker rmi $(docker images -q)
The Vibe: Burning the furniture. How it works:
docker images -q: Lists the IDs of all images.docker rmi: Removes Images.Result: You now have a pristine, empty Docker environment. It’s peaceful. It’s quiet. You have 50GB of free space. Life is good.

