Recovering Your Debian or Ubuntu Server When Docker Fills Up Disk Space: A Comprehensive Guide

Have you ever encountered the dreaded situation where your Docker daemon stops working because your disk is full? It’s a common problem that can bring your containerized applications to a halt. Today, we’re introducing a script that makes recovering from this situation much easier and safer.

The Problem

When Docker fills up your disk space, it creates a cascade of issues:

  1. The Docker daemon stops working
  2. You can’t remove containers or images
  3. Your applications become unavailable
  4. You can’t even use Docker commands to clean up

It’s a classic catch-22: you need Docker running to clean up Docker, but Docker won’t run because there’s no space!

The Solution

We’ve created the Big Bear Debian Docker Disk Recovery Tool - a script that safely guides you through the process of recovering disk space and getting Docker back online. Here’s what makes it special:

:shield: Safety First Approach

  • Never deletes your important container data
  • Preserves all your Docker images
  • Keeps your container configurations intact
  • Interactive process - you’re in control

:arrows_counterclockwise: Step-by-Step Recovery

The script follows a careful, systematic approach:

  1. Initial System Cleanup

    • Clears system journal logs
    • Cleans package manager cache
    • Truncates Docker container logs
    • Offers individual container log cleanup
  2. Docker Cleanup (once running)

    • Removes stopped containers
    • Cleans unused images
    • Removes dangling volumes
    • Cleans up unused networks
  3. Additional Options

    • Option to reinstall Docker
    • Docker Compose installation
    • Comprehensive cleanup statistics

How to Use the Script

  1. First, make sure you’re running as root or with sudo privileges.

  2. Run this one-line command to download and execute the script:

    sudo bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/debian-docker-disk-recovery/run.sh)"
    
  3. Follow the interactive prompts:

    • The script will show current disk usage
    • Each cleanup step requires your confirmation
    • You’ll see the impact of each action
    • Clear statistics show what was cleaned up

Real-World Example

Let’s say your server has run out of space. Here’s how the script helps:

  1. Initial Assessment

    Filesystem      Size  Used  Avail Use% Mounted on
    /dev/sda1       30G   30G   0G   100% /
    
  2. Cleanup Process

    • Clearing logs might free up 500MB
    • Cleaning package cache: another 200MB
    • Truncating Docker logs: 1GB
    • Docker running again!
  3. Further Optimization

    • Remove unused images: 5GB
    • Clean old volumes: 2GB
    • Final result: 8.7GB freed!

Best Practices

To prevent this issue in the future:

  1. Regular Maintenance

    • Schedule regular Docker cleanup
    • Monitor disk usage
    • Set up alerts for low disk space
  2. Proactive Management

    • Use Docker’s built-in prune commands
    • Implement log rotation
    • Consider using volume drivers for data

Conclusion

The Big Bear Debian Docker Disk Recovery Tool turns a stressful situation into a manageable process. It’s designed to be safe, interactive, and effective, helping you get your Docker environment back online quickly.

Support and Community

Have you encountered Docker disk space issues? How do you handle them? Share your experiences in the comments below!