Uninstalling Docker using only the standard package manager commands often leaves behind configuration files, volumes, networks, and other residual data scattered across the filesystem. This guide walks through a thorough removal process to ensure Docker is completely gone from an Ubuntu or Debian-based system.
Note: The steps below will permanently delete all Docker containers, images, volumes, and networks stored on your machine. Back up anything you need before proceeding.
Step 1: Stop the Docker Service
Before removing any packages, stop the Docker daemon to avoid file-in-use errors:
sudo systemctl stop docker
sudo systemctl disable docker
Step 2: Remove Docker Packages
Use apt-get purge to remove the Docker packages along with their configuration files, then autoremove to clean up any unused dependencies:
sudo apt-get purge docker-engine docker docker.io docker-ce docker-ce-cli containerd.io
sudo apt-get autoremove --purge docker-engine docker docker.io docker-ce containerd.io
sudo apt-get autocleanCode language: CSS (css)
The exact package names vary depending on how Docker was installed (from the Ubuntu default repositories versus the official Docker repository). Running the command with all common package names is safe — apt-get will simply skip packages that are not installed.
Step 3: Remove Docker Data Directories
apt-get purge does not remove Docker’s runtime data: images, containers, volumes, and custom networks are stored separately in /var/lib/docker. Remove them manually:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerdCode language: JavaScript (javascript)
Step 4: Remove Residual Configuration and Binary Files
Docker may leave behind configuration files, CLI plugins, and systemd unit files in several locations. Remove them with the following commands:
# Docker configuration directory
sudo rm -rf /etc/docker
# systemd drop-in and service files
sudo rm -rf /etc/systemd/system/docker.service.d
sudo rm -f /etc/systemd/system/docker.service
sudo rm -f /etc/systemd/system/docker.socket
# Docker context and CLI config (per-user)
rm -rf ~/.docker
# Reload systemd after removing unit files
sudo systemctl daemon-reloadCode language: PHP (php)
Step 5: Remove the Docker APT Repository and GPG Key
If you added Docker’s official APT repository, remove it so it does not interfere with future package operations:
# Remove the repository source file
sudo rm -f /etc/apt/sources.list.d/docker.list
# Remove the GPG keyring (path may differ based on how it was added)
sudo rm -f /usr/share/keyrings/docker-archive-keyring.gpg
sudo rm -f /etc/apt/keyrings/docker.gpg
# Update the package index
sudo apt-get updateCode language: PHP (php)
Step 6: Remove Docker Groups and Users
Docker installation creates a docker system group. Remove it if it is no longer needed:
sudo groupdel docker
If the command returns a “group does not exist” error, the group was already removed by the package purge step — that is fine.
Step 7: Verify No Docker Files Remain
Run a filesystem search to confirm that Docker-related files are gone. Be aware that some paths — such as entries under /proc, /sys, and /run — are virtual/pseudo-filesystems and will not persist after a reboot. Entries there do not necessarily indicate a problem:
sudo find / -name '*docker*' 2>/dev/nullCode language: JavaScript (javascript)
After completing the steps above, any remaining results should be limited to virtual kernel filesystems (/proc, /sys) or user-level cache entries. A reboot will clear ephemeral entries in /run and /proc.
Understanding Residual Paths
When the original community question (sourced from askubuntu.com) ran the find command after purging Docker, it discovered references in the following top-level directories:
- /etc — Persistent configuration files not removed by
purge - /lib or /usr/lib — Shared libraries or systemd unit files
- /usr — Binaries, man pages, and CLI plugins
- /var — Runtime data: images, containers, volumes
- /run — Ephemeral runtime sockets and PID files (disappear after reboot)
- /sys — Virtual kernel filesystem entries (disappear after reboot)
- /proc — Virtual process filesystem entries (disappear after reboot)
The steps in this guide address the persistent paths. Entries under /run, /sys, and /proc are managed by the kernel and will be absent after the next reboot.
Quick Reference: Full Removal Script
The commands below combine everything into a single sequence you can run on an Ubuntu/Debian system. Review each line before executing.
#!/usr/bin/env bash
set -e
# 1. Stop and disable the Docker daemon
sudo systemctl stop docker 2>/dev/null || true
sudo systemctl disable docker 2>/dev/null || true
# 2. Purge Docker packages
sudo apt-get purge -y \
docker-engine docker docker.io \
docker-ce docker-ce-cli docker-ce-rootless-extras \
containerd.io
sudo apt-get autoremove --purge -y
sudo apt-get autoclean
# 3. Remove data directories
sudo rm -rf /var/lib/docker /var/lib/containerd
# 4. Remove configuration and service files
sudo rm -rf /etc/docker
sudo rm -f /etc/systemd/system/docker.service \
/etc/systemd/system/docker.socket
sudo rm -rf /etc/systemd/system/docker.service.d
rm -rf ~/.docker
# 5. Remove APT repository and key
sudo rm -f /etc/apt/sources.list.d/docker.list
sudo rm -f /usr/share/keyrings/docker-archive-keyring.gpg
sudo rm -f /etc/apt/keyrings/docker.gpg
sudo apt-get update
# 6. Remove the docker group
sudo groupdel docker 2>/dev/null || true
# 7. Reload systemd
sudo systemctl daemon-reload
echo "Docker removal complete. Reboot to clear any remaining ephemeral entries."Code language: PHP (php)
After rebooting, re-run sudo find / -name '*docker*' 2>/dev/null to confirm a clean state.