Cross‑platform (Linux and macOS) Docker cleanup utility that removes:
- All containers (running or stopped)
- All volumes (including named volumes)
- All images
- Builder cache
Warning: This is destructive and irreversible.
- Docker CLI available on PATH
- Docker daemon reachable for most operations
Make the script executable:
chmod +x /path/to/dclean/dcleanInstall to your PATH (choose one):
# User install (no sudo)
mkdir -p ~/.local/bin
ln -sf /path/to/dclean/dclean ~/.local/bin/dclean
# Or copy
cp /path/to/dclean/dclean ~/.local/bin/dclean
# Ensure ~/.local/bin is in PATH (uncomment your shell):
# bash:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
# zsh:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc# System-wide (requires sudo)
sudo ln -sf /path/to/dclean/dclean /usr/local/bin/dclean
# Or copy
sudo cp /path/to/dclean/dclean /usr/local/bin/dcleanVerify:
dclean helpMake the script executable:
chmod +x /path/to/dclean/dcleanInstall to your PATH (choose one):
# System-wide (recommended)
sudo ln -sf /path/to/dclean/dclean /usr/local/bin/dclean
# Or copy
sudo cp /path/to/dclean/dclean /usr/local/bin/dclean# Optional: user install (add ~/.local/bin to PATH)
mkdir -p ~/.local/bin
ln -sf /path/to/dclean/dclean ~/.local/bin/dclean
# Or copy
cp /path/to/dclean/dclean ~/.local/bin/dclean
# Ensure ~/.local/bin is in PATH (uncomment your shell):
# bash:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc
# zsh:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrcVerify:
dclean helpdclean # show usage/help
dclean all # containers → volumes → images → cache
dclean containers # stop and remove all containers (force)
dclean volumes # remove all volumes
dclean images # remove all images (force)
dclean cache # prune builder cacheExamples:
dclean
dclean all
dclean containers
dclean images
dclean volumes
dclean cache- Designed to be destructive for a clean slate
- Empty-result handling prevents errors like:
docker: 'docker rm' requires at least 1 argument
- Uses chunking with
xargs -n 100to avoid long argument lists - Avoids GNU-only flags so it works on macOS and Linux
- Falls back to
docker system prune -fifdocker builder prune -ffails
MIT — see LICENSE.