{"id":49565347,"url":"https://github.com/ujas-dev/docker-cleaner-script","last_synced_at":"2026-05-03T11:34:53.656Z","repository":{"id":319352139,"uuid":"1078452220","full_name":"ujas-dev/docker-cleaner-script","owner":"ujas-dev","description":"A powerful shell script to clean Docker containers, images, volumes, build caches, and local Kubernetes clusters (minikube, kind) in WSL and Docker Desktop environments, with advanced features like dry-run, age filtering, and selective cleanup.","archived":false,"fork":false,"pushed_at":"2025-10-17T19:02:08.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-18T21:24:45.444Z","etag":null,"topics":["automation","cleanup","devops","docker","docker-desktop","kubernetes","shell-script","system-administration","wsl"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ujas-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-17T18:55:09.000Z","updated_at":"2025-10-17T19:02:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"a89e2f94-1814-40b6-b513-7764c720593a","html_url":"https://github.com/ujas-dev/docker-cleaner-script","commit_stats":null,"previous_names":["ujas-dev/docker-cleaner-script"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ujas-dev/docker-cleaner-script","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujas-dev%2Fdocker-cleaner-script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujas-dev%2Fdocker-cleaner-script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujas-dev%2Fdocker-cleaner-script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujas-dev%2Fdocker-cleaner-script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ujas-dev","download_url":"https://codeload.github.com/ujas-dev/docker-cleaner-script/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ujas-dev%2Fdocker-cleaner-script/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32567449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","cleanup","devops","docker","docker-desktop","kubernetes","shell-script","system-administration","wsl"],"created_at":"2026-05-03T11:34:53.066Z","updated_at":"2026-05-03T11:34:53.650Z","avatar_url":"https://github.com/ujas-dev.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker and Kubernetes Cleaner\n\nA robust, feature-rich shell script to clean up Docker containers, images, volumes, build caches, and local Kubernetes clusters (minikube, kind) in WSL and Docker Desktop environments. Designed for developers and system administrators, this script provides granular control over cleanup with options for dry-run, verbose logging, age-based filtering, selective resource targeting, and more. Use with caution, as it can delete critical Docker and Kubernetes resources.\n\n## Features\n\n- **Comprehensive Cleanup**: Removes Docker containers, images, volumes, build caches, builders, and local Kubernetes clusters (minikube, kind).\n- **WSL and Docker Desktop Support**: Handles WSL-specific paths and Docker Desktop build history cleanup.\n- **Dry-Run Mode**: Simulates cleanup without deleting anything (`--dry-run`).\n- **Verbose Logging**: Detailed output for each action (`--verbose`).\n- **Age-Based Filtering**: Removes resources older than a specified number of days (`--older-than DAYS`).\n- **Selective Cleanup**: Target specific resource types (e.g., `--only-containers`, `--only-images`).\n- **Dangling Resource Cleanup**: Removes unused images, exited containers, dangling volumes, networks, and build caches (`--only-dangling`).\n- **Interactive Confirmation**: Prompts before major actions (`--confirm`).\n- **Container Log Cleaning**: Truncates Docker container logs to free space (`--clean-logs`).\n- **Cron-Friendly**: Quiet mode for automated runs (`--quiet`).\n- **Exclusion Options**: Protect specific containers, images, volumes, builders, or clusters (e.g., `--exclude-containers \"c1 c2\"`).\n- **Protect Current Directory**: Automatically excludes resources tied to the current directory's Docker Compose project (`--protect-current-dir`).\n- **Docker Desktop Reset**: Optional reset of all Docker Desktop data (`--reset-docker-desktop`, destructive).\n- **Summary Table**: Outputs a detailed table of removed and excluded resources.\n\n## Installation\n\n1. **Download the Script**:\n   ```bash\n   wget https://raw.githubusercontent.com/yourusername/docker-k8s-cleaner/main/clean_docker.sh\n   ```\n\n2. **Make Executable**:\n   ```bash\n   chmod +x clean_docker.sh\n   ```\n\n3. **Ensure Dependencies**:\n   - Docker CLI (compatible with Docker Desktop on Windows or native Linux).\n   - Optional: `minikube` and `kind` for Kubernetes cleanup.\n   - WSL2 (for Windows users running Docker Desktop).\n   - Basic Unix tools (`awk`, `grep`, `date`, `wc`).\n\n4. **Verify Docker Setup**:\n   - Run `docker --version` to ensure Docker is installed.\n   - For WSL, ensure Docker Desktop is configured with WSL2 integration (Settings \u003e Resources \u003e WSL Integration).\n\n## Usage\n\nRun the script from your WSL or Linux terminal. Use options to customize the cleanup process.\n\n### Basic Usage\n```bash\n./clean_docker.sh\n```\nCleans all Docker and Kubernetes resources (except excluded ones).\n\n### Options\n```bash\n./clean_docker.sh [options]\nOptions:\n  --exclude-containers \"c1 c2\"   Space-separated container IDs or names to exclude\n  --exclude-images \"i1 i2\"       Space-separated image IDs or repo:tags to exclude\n  --exclude-volumes \"v1 v2\"      Space-separated volume names to exclude\n  --exclude-builders \"b1 b2\"     Space-separated builder names to exclude\n  --exclude-minikube \"p1 p2\"     Space-separated minikube profiles to exclude\n  --exclude-kind \"c1 c2\"         Space-separated kind clusters to exclude\n  --protect-current-dir          Protect resources associated with the current directory (docker-compose projects)\n  --reset-docker-desktop         Reset Docker Desktop data (WARNING: removes all Docker data)\n  --dry-run                      Simulate cleanup without deleting\n  --verbose                      Log detailed actions\n  --older-than DAYS              Only remove resources older than DAYS days\n  --only-containers              Only clean containers\n  --only-images                  Only clean images\n  --only-volumes                 Only clean volumes\n  --only-builders                Only clean builders and build history\n  --only-minikube                Only clean minikube profiles\n  --only-kind                    Only clean kind clusters\n  --only-dangling                Only clean dangling/unused resources\n  --only-logs                    Only clean container logs\n  --confirm                      Prompt for confirmation before major actions\n  --clean-logs                   Clean (truncate) Docker container logs\n  --quiet                        Suppress output (for cron jobs)\n```\n\n### Examples\n- **Dry-run with verbose output**:\n  ```bash\n  ./clean_docker.sh --dry-run --verbose\n  ```\n  Simulates cleanup and logs every action.\n\n- **Clean containers older than 30 days**:\n  ```bash\n  ./clean_docker.sh --only-containers --older-than 30\n  ```\n\n- **Clean dangling resources and logs quietly (for cron)**:\n  ```bash\n  ./clean_docker.sh --quiet --only-dangling --clean-logs\n  ```\n\n- **Protect current directory and exclude a builder**:\n  ```bash\n  ./clean_docker.sh --protect-current-dir --exclude-builders \"my-builder\"\n  ```\n\n- **Reset Docker Desktop (destructive)**:\n  ```bash\n  ./clean_docker.sh --reset-docker-desktop --confirm\n  ```\n\n### Cron Setup\nTo automate cleanup (e.g., nightly at 2 AM), edit your crontab:\n```bash\ncrontab -e\n```\nAdd:\n```bash\n0 2 * * * /path/to/clean_docker.sh --quiet --older-than 30 --only-dangling --clean-logs\n```\n\n## Output\nThe script outputs a summary table of removed and excluded resources:\n```\nCleanup Summary:\nResource Type             | Removed  | Excluded\n------------------------- | -------- | --------\nContainers                | 5        | 2\nImages                    | 10       | 1\nVolumes                   | 3        | 0\nBuilders (Processed)      | 2        | 1\nBuilders (Removed)        | 1        | N/A\nMinikube Profiles         | 0        | 0\nKind Clusters             | 1        | 0\nDangling Images           | 4        | N/A\nDangling Containers       | 2        | N/A\nDangling Volumes          | 1        | N/A\nDangling Networks         | 1        | N/A\nDangling Build Cache      | 1        | N/A\nCleaned Logs              | 5        | N/A\n```\n\n## Troubleshooting\n\n- **Error: `unknown flag: --format`**:\n  - The script avoids `--format` for compatibility with older Docker versions (\u003c19.03). If you encounter issues, update Docker Desktop or verify your Docker CLI version (`docker --version`).\n- **Error: `printf: 0 0: not completely converted`**:\n  - Fixed in the latest version by sanitizing counter variables. If it persists, run with `--verbose --dry-run` and share the output.\n- **Build History Persists in Docker Desktop**:\n  - Restart Docker Desktop.\n  - Manually delete `$HOME/.docker/buildx` (WSL) and `%USERPROFILE%\\.docker\\buildx` (Windows).\n  - Use `--reset-docker-desktop` (back up critical data first).\n- **Permission Issues**:\n  - Run with `sudo` in WSL: `sudo ./clean_docker.sh`.\n  - Ensure Docker Desktop WSL2 integration is enabled.\n- **Slow Performance**:\n  - Increase WSL2 memory in `%USERPROFILE%\\.wslconfig`:\n    ```ini\n    [wsl2]\n    memory=8GB\n    ```\n- **Debugging**:\n  - Run with verbose mode: `./clean_docker.sh --verbose --dry-run`.\n  - Check Docker version: `docker --version` and `docker buildx version`.\n  - Share output with the maintainer for further assistance.\n\n## System Requirements\n- **OS**: WSL2 (Windows 11) or Linux.\n- **Hardware**: 16 GB RAM recommended (script is optimized for your 12th Gen Intel i7-1255U, 16 GB RAM setup).\n- **Software**: Docker CLI, Docker Desktop (for Windows), optional minikube/kind.\n- **Docker Version**: Compatible with older versions (pre-19.03), but 19.03+ recommended for optimal performance.\n\n## Contributing\nContributions are welcome! Fork the repository, make changes, and submit a pull request. Please test changes in a WSL or Linux environment and ensure compatibility with Docker Desktop.\n\n## License\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n- Built for developers and DevOps engineers managing Docker and Kubernetes in WSL and Docker Desktop environments.\n- Inspired by community tools like `docker-clean` and Stack Overflow solutions for Docker resource management.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fujas-dev%2Fdocker-cleaner-script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fujas-dev%2Fdocker-cleaner-script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fujas-dev%2Fdocker-cleaner-script/lists"}