83 lines
2.8 KiB
Markdown
83 lines
2.8 KiB
Markdown
# Docker Factory Reset Script for Ubuntu
|
|
|
|
A comprehensive Python script that completely resets Docker to a fresh installation state on Ubuntu systems. This script removes all containers, images, volumes, networks, build cache, and even wipes the Docker data directories to give you a clean slate.
|
|
|
|
## 🚨 Warning
|
|
|
|
**This script is EXTREMELY DESTRUCTIVE!**
|
|
|
|
It will permanently delete:
|
|
- ✗ All Docker containers (running and stopped)
|
|
- ✗ All Docker images
|
|
- ✗ All Docker volumes (including all data stored in them)
|
|
- ✗ All custom Docker networks
|
|
- ✗ All build cache
|
|
- ✗ All Docker system data (`/var/lib/docker` and `/var/lib/containerd`)
|
|
|
|
**There is NO undo. All data will be permanently lost.**
|
|
|
|
Only use this script if you:
|
|
- Want to completely reset Docker to a fresh state
|
|
- Are experiencing issues that require a clean Docker installation
|
|
- Are decommissioning a system and want to clean up Docker
|
|
- Understand that ALL Docker data will be lost
|
|
|
|
## 📋 Features
|
|
|
|
- ✅ **Real-time output**: See exactly what's happening as commands execute
|
|
- ✅ **Progress indicators**: Visual progress bars for batch operations
|
|
- ✅ **Step-by-step execution**: Clear indication of each phase
|
|
- ✅ **Safety confirmation**: Requires explicit confirmation before proceeding
|
|
- ✅ **Comprehensive cleanup**: Removes everything Docker-related
|
|
- ✅ **Service management**: Properly stops and restarts Docker daemon
|
|
- ✅ **Final state report**: Shows the clean state after reset
|
|
- ✅ **Execution time tracking**: Reports how long the reset took
|
|
|
|
## 🔧 Requirements
|
|
|
|
### System Requirements
|
|
- **Operating System**: Ubuntu (18.04, 20.04, 22.04, 24.04 or later)
|
|
- **Docker**: Must be installed (any version)
|
|
- **Python**: Python 3.6 or later (usually pre-installed on Ubuntu)
|
|
- **Privileges**: Must be run as root (using `sudo`)
|
|
|
|
### Dependencies
|
|
All dependencies are part of Python's standard library:
|
|
- `subprocess` - For running system commands
|
|
- `sys` - For system operations
|
|
- `os` - For file system operations
|
|
- `time` - For timing and delays
|
|
|
|
No additional packages need to be installed.
|
|
|
|
## 🚀 Usage
|
|
|
|
Run the script with sudo:
|
|
|
|
```bash
|
|
sudo python3 docker_full_factory_reset.py
|
|
```
|
|
|
|
The script will ask you to type `RESET_DOCKER_UBUNTU` to confirm.
|
|
|
|
## 📖 What Each Step Does
|
|
|
|
1. **Containers**: Stops and removes all containers
|
|
2. **Images**: Removes all images
|
|
3. **Networks**: Removes custom networks (keeps default ones)
|
|
4. **Volumes**: Removes all volumes
|
|
5. **Prune**: Clears build cache and system artifacts
|
|
6. **Stop services**: Stops `docker` and `containerd`
|
|
7. **Delete directories**: Removes `/var/lib/docker` and `/var/lib/containerd`
|
|
8. **Start services**: Restarts Docker and verifies with `docker info`
|
|
|
|
## 🔍 Verify After Reset
|
|
|
|
```bash
|
|
docker run hello-world
|
|
```
|
|
|
|
## ⚠ Final Warning
|
|
|
|
This script deletes **ALL** Docker data. Back up anything important first.
|