162 lines
5.0 KiB
Markdown
Executable File
162 lines
5.0 KiB
Markdown
Executable File
# Docker Tools - Bash Scripts
|
|
|
|
This directory contains enhanced bash scripts that match the functionality of the Go version (`docwell.go`). All scripts are version 2.6.2 and share a common library.
|
|
|
|
## Architecture
|
|
|
|
All scripts source `lib/common.sh`, which provides:
|
|
- Color output with `NO_COLOR` support
|
|
- Spinner/progress animations (braille frames)
|
|
- Unified logging (`log_info`, `log_warn`, `log_error`, `log_success`, `log_header`)
|
|
- Config file loading from `~/.config/docwell/config`
|
|
- Compose file detection, stack discovery, validation
|
|
- Cleanup traps (signal handling for Ctrl+C)
|
|
- Dry-run wrapper (`run_or_dry`)
|
|
- Bounded parallel execution
|
|
- SSH helpers
|
|
|
|
> **Note**: `docker-stack.sh` and `docker-update.sh` have been combined into `docker-manager.sh`. The old scripts are kept for backward compatibility but `docker-manager.sh` is recommended for new usage.
|
|
|
|
## Scripts Overview
|
|
|
|
### docker-backup.sh
|
|
Backup Docker stacks with compression.
|
|
|
|
**Usage:**
|
|
```bash
|
|
./docker-backup.sh --list # List stacks
|
|
./docker-backup.sh --all # Backup all stacks
|
|
./docker-backup.sh --stack myapp # Backup specific stack
|
|
./docker-backup.sh --all --quiet --yes # Non-interactive backup
|
|
./docker-backup.sh --all --dry-run # Preview without executing
|
|
```
|
|
|
|
### docker-cleanup.sh
|
|
Clean up Docker resources (containers, images, volumes, networks, build cache).
|
|
|
|
**Usage:**
|
|
```bash
|
|
./docker-cleanup.sh --containers # Remove stopped containers
|
|
./docker-cleanup.sh --all --yes # Run all cleanups
|
|
./docker-cleanup.sh --images --volumes # Remove images and volumes
|
|
./docker-cleanup.sh --all --dry-run # Preview cleanup
|
|
```
|
|
|
|
### docker-manager.sh
|
|
Combined stack management and update functionality.
|
|
|
|
**Usage:**
|
|
```bash
|
|
./docker-manager.sh --list # List all stacks
|
|
./docker-manager.sh --start myapp # Start a stack
|
|
./docker-manager.sh --stop myapp # Stop a stack
|
|
./docker-manager.sh --check # Check for updates
|
|
./docker-manager.sh --update-all # Update all stacks
|
|
./docker-manager.sh --update myapp # Update specific stack
|
|
./docker-manager.sh --auto --yes # Auto-update all stacks
|
|
```
|
|
|
|
### docker-migrate.sh
|
|
Migrate Docker services between servers.
|
|
|
|
**Usage:**
|
|
```bash
|
|
./docker-migrate.sh myapp --dest user@remote-host
|
|
./docker-migrate.sh --service myapp --dest user@remote --method rsync
|
|
./docker-migrate.sh --service myapp --dest remote --bwlimit 50 --retries 5
|
|
./docker-migrate.sh --service myapp --dest remote --dry-run
|
|
```
|
|
|
|
### docker-auto-migrate.sh
|
|
Migrate ALL stacks to a destination host.
|
|
|
|
**Usage:**
|
|
```bash
|
|
./docker-auto-migrate.sh --dest 10.0.0.2 --dest-user admin
|
|
./docker-auto-migrate.sh --dest remote-host --method rsync --dry-run
|
|
```
|
|
|
|
## Common Options
|
|
|
|
All scripts support:
|
|
- `--version` — Show version information
|
|
- `--help, -h` — Show help message
|
|
- `--quiet, -q` — Suppress non-error output
|
|
- `--yes, -y` — Auto-confirm all prompts
|
|
- `--dry-run` — Preview without executing
|
|
- `--install-deps` — Auto-install missing dependencies (requires root)
|
|
- `--log FILE` — Custom log file path
|
|
|
|
## Configuration
|
|
|
|
### Config File
|
|
Scripts load settings from `~/.config/docwell/config` (same as Go version):
|
|
```ini
|
|
StacksDir="/opt/stacks"
|
|
BackupBase="/storage/backups/docker-myhost"
|
|
LogFile="/tmp/docwell/docwell.log"
|
|
OldHost="10.0.0.10"
|
|
OldPort="22"
|
|
OldUser="admin"
|
|
BandwidthMB="50"
|
|
TransferRetries="3"
|
|
```
|
|
|
|
### Environment Variables
|
|
Config file values can be overridden by environment variables:
|
|
- `STACKS_DIR` — Stacks directory (default: `/opt/stacks`)
|
|
- `BACKUP_BASE` — Backup base directory (default: `/storage/backups/docker-$HOSTNAME`)
|
|
- `LOG_FILE` — Log file path (default: `/tmp/docwell/docwell.log`)
|
|
- `NO_COLOR` — Disable color output when set
|
|
|
|
Migration-specific:
|
|
- `OLD_HOST`, `OLD_PORT`, `OLD_USER` — Source server defaults
|
|
- `NEW_HOST`, `NEW_PORT`, `NEW_USER` — Destination server defaults
|
|
|
|
## Comparison with Go Version
|
|
|
|
| Feature | Bash | Go |
|
|
|---|---|---|
|
|
| CLI Flags | ✅ | ✅ |
|
|
| Interactive Mode | ✅ | ✅ |
|
|
| Spinner/Progress | ✅ | ✅ |
|
|
| Config File | ✅ | ✅ |
|
|
| Dry-Run | ✅ | ✅ |
|
|
| Signal Handling | ✅ | ✅ |
|
|
| Transfer Methods | ✅ rsync, tar, rclone | ✅ rsync, tar, rclone |
|
|
| Parallel Operations | ✅ Bounded | ✅ Full |
|
|
| Post-Migration Verify | ✅ | ✅ |
|
|
| Bandwidth Limiting | ✅ | ✅ |
|
|
| NO_COLOR Support | ✅ | ❌ |
|
|
|
|
## Examples
|
|
|
|
### Automated Backup (cron)
|
|
```bash
|
|
0 2 * * * /usr/local/bin/docker-backup.sh --all --quiet --yes
|
|
```
|
|
|
|
### Weekly Cleanup (cron)
|
|
```bash
|
|
0 2 * * 0 /usr/local/bin/docker-cleanup.sh --all --yes --quiet
|
|
```
|
|
|
|
### Update Check Script
|
|
```bash
|
|
#!/bin/bash
|
|
/usr/local/bin/docker-manager.sh --check --quiet
|
|
```
|
|
|
|
## Notes
|
|
|
|
- All scripts require Docker and Docker Compose
|
|
- Some operations may require root or sudo
|
|
- Scripts use `set -euo pipefail` for strict error handling
|
|
- Color output disabled when `NO_COLOR=1` is set or stdout is not a terminal
|
|
|
|
## See Also
|
|
|
|
- Go version: `../go/docwell.go`
|
|
- Shared library: `lib/common.sh`
|
|
- Test stack: `../test-stack/`
|