How to Completely Uninstall Docker
In this tutorial, we will show you how to completely uninstall Docker. Docker has revolutionized containerization technology, but there comes a time when you might need to remove it entirely from your Linux system. Whether you’re troubleshooting installation issues, freeing up disk space, or switching to alternative containerization solutions, knowing how to completely uninstall Docker is crucial for maintaining a clean and efficient system.
Many users make the mistake of thinking that a simple package removal will suffice. However, Docker creates an extensive footprint across your system, leaving behind containers, images, volumes, networks, and configuration files that can consume significant disk space—often exceeding 10 GB of residual data. These remnants can cause conflicts with future installations and impact system performance.
This comprehensive guide provides expert-tested methods for completely removing Docker from various Linux distributions. You’ll learn systematic approaches to eliminate all Docker components, clean up system files, and verify complete removal. Every step includes verification commands and troubleshooting tips to ensure nothing is left behind.
Understanding Docker’s System Architecture
Before diving into the removal process, it’s essential to understand how Docker integrates with your Linux system. Docker isn’t just a single application—it’s a complex ecosystem of interconnected components that embed themselves throughout your system.
Docker Components Overview
Docker consists of several core components that work together to provide containerization capabilities. The Docker Engine serves as the runtime environment, while the Docker CLI provides the command-line interface for user interaction. Containerd acts as the container runtime, managing the complete container lifecycle from image transfer to container execution.
The distinction between Docker Desktop and Docker Engine is crucial for removal. Docker Desktop provides a graphical interface and additional features primarily designed for development environments, while Docker Engine offers the core containerization functionality typically used in production servers.
File System Footprint Analysis
Docker creates numerous directories and files across your system. The primary storage location is /var/lib/docker
, which contains images, containers, volumes, and other runtime data. Configuration files reside in /etc/docker
, containing daemon settings and security configurations. User-specific data is stored in ~/.docker
, including authentication credentials and client configurations.
Additional files scatter throughout the system, including AppArmor profiles, systemd service files, and network configuration data. Understanding this distribution helps ensure complete removal without missing critical components.
Process and Service Dependencies
Docker integrates deeply with system services through systemd units. The Docker daemon runs as a background service, while the Docker socket provides communication channels. Container runtimes create additional processes that may persist even after stopping the main Docker service.
Network bridges and iptables rules configured by Docker can affect system networking. These configurations require manual cleanup to restore the original system state.
Pre-Removal Assessment and Preparation
Proper preparation prevents data loss and ensures a smooth removal process. Taking inventory of your Docker installation and backing up critical data protects against unintended consequences.
System Inventory and Documentation
Start by documenting your current Docker installation. Run the following command to list all Docker-related packages:
dpkg -l | grep -i docker
For RPM-based systems, use:
rpm -qa | grep -i docker
This inventory helps identify all components that need removal and provides a reference for troubleshooting if issues arise.
Next, document your containers and images. List all containers with:
docker ps -a
Display all images using:
docker images
Record any critical containers or custom images you might need to preserve or recreate later.
Critical Data Backup Procedures
Before proceeding with removal, backup any important containers or images. Export containers to tar files using:
docker export container_name > container_backup.tar
Save images with:
docker save image_name > image_backup.tar
For custom configurations, backup the entire /etc/docker
directory:
sudo cp -r /etc/docker /backup/docker-config
Document any custom networks, volumes, or specialized configurations that might be difficult to recreate.
Risk Assessment and Warnings
Complete Docker removal is irreversible without backups. All containers, images, volumes, and custom configurations will be permanently deleted. Ensure no critical applications depend on Docker services before proceeding.
Verify you have sufficient privileges to perform system-level operations. Most removal commands require sudo access. Consider the impact on other users who might be using Docker on shared systems.
Safe Container and Image Cleanup
Before removing Docker packages, properly clean up containers and images to prevent data corruption and ensure smooth removal.
Container Management Before Removal
Begin by listing all containers to understand what will be removed:
docker ps -a
Stop all running containers gracefully:
docker stop $(docker ps -q)
If containers refuse to stop, force termination:
docker kill $(docker ps -q)
Remove all containers:
docker rm $(docker ps -a -q)
For systems with many containers, use the force flag to expedite removal:
docker rm -f $(docker ps -a -q)
Image and Volume Cleanup
Remove all images from your system:
docker rmi $(docker images -q)
Force removal of images referenced by multiple tags:
docker rmi -f $(docker images -q)
Clean up volumes and networks:
docker volume prune -f
docker network prune -f
Perform a comprehensive system cleanup:
docker system prune -a --volumes -f
Network and Build Cache Cleanup
Remove custom networks that might interfere with system networking:
docker network ls
docker network rm $(docker network ls -q)
Clear build cache and temporary files:
docker builder prune -a -f
Verify complete resource removal by running:
docker system df
This command should show minimal or zero usage across all categories.
Complete Docker Package Removal
With containers and images cleaned up, proceed to remove Docker packages and services from your system.
Service Termination Process
Stop all Docker services before package removal:
sudo systemctl stop docker
sudo systemctl stop docker.socket
sudo systemctl stop containerd
Disable automatic startup to prevent services from restarting:
sudo systemctl disable docker
sudo systemctl disable docker.socket
sudo systemctl disable containerd
Verify services are stopped:
sudo systemctl status docker
sudo systemctl status docker.socket
sudo systemctl status containerd
Package Identification and Removal
For Debian-based systems (Ubuntu, Debian), remove Docker packages:
sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Use wildcards to catch any remaining Docker packages:
sudo apt-get remove --purge 'docker*'
For Red Hat-based systems (CentOS, RHEL, Fedora):
sudo dnf remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Or using yum on older systems:
sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Dependency Cleanup
Remove orphaned packages and dependencies:
sudo apt-get autoremove -y --purge
Clean package cache:
sudo apt-get clean
For RPM-based systems:
sudo dnf autoremove
sudo dnf clean all
Alternative Removal Methods
If Docker was installed via Snap:
sudo snap remove docker
For Flatpak installations:
flatpak uninstall org.docker.Docker
Check for and remove any remaining Docker-related packages:
apt list --installed | grep docker
System-Level File and Directory Cleanup
Package removal doesn’t eliminate all Docker files. Manual cleanup of directories and configuration files ensures complete removal.
Core Docker Directories
Remove the primary Docker data directory:
sudo rm -rf /var/lib/docker
Delete containerd data:
sudo rm -rf /var/lib/containerd
Remove configuration directories:
sudo rm -rf /etc/docker
sudo rm -rf /etc/containerd
User and System Configuration Files
Clean up user-specific Docker configurations:
rm -rf ~/.docker
Remove Docker socket files:
sudo rm -f /var/run/docker.sock
sudo rm -f /var/run/docker.pid
Delete AppArmor profiles:
sudo rm -f /etc/apparmor.d/docker*
Remove systemd service files:
sudo rm -f /etc/systemd/system/docker*
sudo rm -f /lib/systemd/system/docker*
sudo rm -f /usr/lib/systemd/system/docker*
Network and Security Cleanup
Docker modifies iptables rules and creates network bridges. Remove Docker-specific iptables rules:
sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -F
sudo iptables -X
Remove Docker network bridges:
sudo ip link delete docker0
Reset firewall rules if using ufw:
sudo ufw --force reset
Group and User Management
Remove the Docker group:
sudo groupdel docker
Note that this command might fail if the group doesn’t exist or still has members. Check group membership first:
getent group docker
Remove users from the Docker group manually if needed:
sudo gpasswd -d username docker
Repository and Source Management
Complete removal includes eliminating Docker repositories and signing keys to prevent future automatic updates.
APT Source Removal
Remove Docker repository files:
sudo rm -f /etc/apt/sources.list.d/docker.list
sudo rm -f /etc/apt/sources.list.d/docker-ce.list
Delete GPG keys:
sudo rm -f /etc/apt/keyrings/docker.gpg
sudo rm -f /etc/apt/keyrings/docker.asc
sudo rm -f /usr/share/keyrings/docker*
Package Manager Cleanup
Update package lists after removing repository sources:
sudo apt-get update
Verify no Docker references remain in package lists:
apt-cache search docker
For RPM-based systems, remove repository files:
sudo rm -f /etc/yum.repos.d/docker*
sudo rm -f /etc/dnf/repos.d/docker*
Clean repository metadata:
sudo dnf clean all
sudo dnf makecache
Multi-Platform Considerations
Different Linux distributions and installation methods require specific approaches for complete Docker removal.
Ubuntu and Debian Variations
Ubuntu and Debian systems might have Docker installed through different channels. Check for snap packages:
snap list | grep docker
Remove snap-installed Docker:
sudo snap remove docker
Debian systems sometimes use different package names. Verify removal with:
dpkg -l | grep -i docker
Red Hat and CentOS Systems
Red Hat-based systems use different package managers and might have SELinux policies related to Docker. Remove SELinux policies:
sudo semanage fcontext -d -t container_file_t "/var/lib/docker(/.*)?"
sudo restorecon -R /var/lib/docker
Check for podman, which might be installed alongside Docker:
dnf list installed | grep podman
Docker Desktop vs. Docker Engine
Docker Desktop creates additional files in user directories. Remove Desktop-specific files:
rm -rf ~/.docker/desktop
rm -rf ~/Library/Group\ Containers/group.com.docker
Check for Desktop application files:
find /opt -name "*docker*" -type d
Verification and Troubleshooting
Thorough verification ensures complete removal and helps identify any remaining components.
Complete Removal Verification
Test that Docker commands are no longer available:
docker --version
This should return “command not found” or similar error.
Check service status:
sudo systemctl status docker
sudo systemctl status docker.socket
sudo systemctl status containerd
Verify file system cleanup:
find / -name "*docker*" -type f 2>/dev/null
find / -name "*docker*" -type d 2>/dev/null
Common Issues and Solutions
Permission Denied Errors: If you encounter permission errors, ensure you’re using sudo for system-level operations:
sudo rm -rf /var/lib/docker
Service Still Running: If services persist after stopping, force kill processes:
sudo pkill -f docker
sudo pkill -f containerd
Locked Files: If files are locked, identify and stop processes using them:
sudo lsof | grep docker
sudo fuser -v /var/lib/docker
System Health Verification
Check disk space reclamation:
df -h
Verify network configuration restoration:
ip link show
sudo iptables -L
Look for any remaining Docker-related processes:
ps aux | grep docker
ps aux | grep containerd
Troubleshooting Incomplete Removal
If verification reveals remaining Docker components, manually remove them:
sudo find / -name "*docker*" -exec rm -rf {} \;
Use caution with this command as it removes all files and directories containing “docker” in their names.
Check for hidden configuration files:
find ~/.config -name "*docker*" -type f
Remove any discovered files:
rm -rf ~/.config/docker
Post-Removal Considerations and Best Practices
After successful Docker removal, optimize your system and establish practices to prevent future issues.
System Optimization After Removal
Reclaim disk space by cleaning temporary files:
sudo apt-get autoclean
sudo apt-get autoremove
Update system packages:
sudo apt-get update && sudo apt-get upgrade
Restart your system to ensure all changes take effect:
sudo reboot
Preventing Future Issues
Document your removal process for future reference. Create a removal script combining all commands for easy reuse:
#!/bin/bash
# Docker Complete Removal Script
# Stop services
sudo systemctl stop docker docker.socket containerd
# Remove packages
sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli containerd.io
# Clean directories
sudo rm -rf /var/lib/docker /var/lib/containerd /etc/docker
# Remove user configs
rm -rf ~/.docker
# Clean up
sudo apt-get autoremove -y --purge
Consider alternative containerization solutions if needed, such as Podman or LXC, which offer different architectural approaches.
Monitoring and Maintenance
Implement regular system cleanup procedures:
sudo apt-get autoclean
sudo apt-get autoremove
Monitor disk space usage:
du -sh /var/lib/docker 2>/dev/null || echo "Docker directory successfully removed"
Check for Docker-related processes periodically:
ps aux | grep -i docker