2.8 KiB
2.8 KiB
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/dockerand/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 commandssys- For system operationsos- For file system operationstime- For timing and delays
No additional packages need to be installed.
🚀 Usage
Run the script with sudo:
sudo python3 docker_full_factory_reset.py
The script will ask you to type RESET_DOCKER_UBUNTU to confirm.
📖 What Each Step Does
- Containers: Stops and removes all containers
- Images: Removes all images
- Networks: Removes custom networks (keeps default ones)
- Volumes: Removes all volumes
- Prune: Clears build cache and system artifacts
- Stop services: Stops
dockerandcontainerd - Delete directories: Removes
/var/lib/dockerand/var/lib/containerd - Start services: Restarts Docker and verifies with
docker info
🔍 Verify After Reset
docker run hello-world
⚠ Final Warning
This script deletes ALL Docker data. Back up anything important first.