Support >
  About cloud server >
  How to completely uninstall Docker on an Ubuntu server

How to completely uninstall Docker on an Ubuntu server

Time : 2025-12-22 17:07:55
Edit : DNS.COM

The need to uninstall Docker in a production environment on an Ubuntu server might arise due to version upgrades, switching container runtimes (such as switching to containerd), or server resource reclamation. Unlike desktop environments, uninstallation on a server must be thorough and cautious, ensuring the removal of all related components, cleanup of stored data, and avoiding impact on other services. A complete uninstallation process involves more than just executing `apt remove docker.io`; it includes service stopping, package removal, data cleanup, and system status verification.

First, before starting any uninstallation operations, all running Docker containers and related services must be stopped. This is to prevent data corruption or service interruption. You can view currently running containers and stop them via the command line:

# View currently running containers

sudo docker ps

# Stop all running containers

sudo docker stop $(sudo docker ps -aq)

# Verify all containers have stopped (there should be no output or only the container ID with an Exited status)

sudo docker ps -a

Next, stop the Docker daemon service itself. On Ubuntu, Docker typically runs as a system service, managed using `systemctl`:

# Stop the Docker service

sudo systemctl stop docker

sudo systemctl stop docker.socket

# Disable the service to prevent it from starting automatically after a system reboot

sudo systemctl disable docker docker.socket

These commands ensure the Docker engine is completely stopped, preparing for a safe uninstall. Now you can begin removing the Docker packages. The uninstallation commands will vary slightly depending on how you initially installed Docker. The most common method is installation via the official Docker APT repository, in which case multiple packages need to be removed. Execute the following commands to remove the main components:

# Remove the Docker engine, command-line tools, and other core packages

sudo apt remove --purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

The `--purge` parameter is crucial; it tells APT to remove the configuration files along with the packages. If only `remove` is used, the configuration files will remain on the system, potentially affecting subsequent reinstallations. If you're unsure about your initial installation method, or if you're using an older version of docker.io from the Ubuntu repository, you can try removing the generic package name:

# Try removing all possible Docker-related packages

sudo apt remove --purge docker docker.io containerd runc

After removing the packages, you also need to clean up data and storage that APT won't automatically delete. Docker generates images, container data, volumes, and network configurations during runtime, which are typically stored in the `/var/lib/docker/` directory. To thoroughly clean up, you need to delete this directory:

# Delete all Docker images, containers, volumes, and cache data

sudo rm -rf /var/lib/docker

sudo rm -rf /var/lib/containerd

Note that the `rm -rf` command permanently deletes all data in these directories, including all your containers, images, volumes, and build caches. If there is any data you need to retain, be sure to back it up before deleting it. In addition, Docker may have left configuration files in other locations, which can be cleaned up as well:

# Delete any existing configuration files

sudo rm -rf /etc/docker

# Remove the docker user group (if it exists and no other users are using it)

sudo groupdel docker

Some users may have installed Docker via Snap, especially on some Ubuntu variants. If this is the case, the uninstallation method is completely different:

# Check if it was installed via Snap

snap list | grep docker

# If found, remove it via Snap

sudo snap remove docker

After completing all uninstallation steps, a system cleanup and verification should be performed. First, update the APT cache to ensure the system is up-to-date:

# Update the package list

sudo apt update

# Automatically remove unnecessary dependencies

sudo apt autoremove -y

# Clean the APT cache

sudo apt autoclean

Now verify that Docker has been completely removed. Trying to run Docker commands should result in a "command not found" error:

# These commands should now fail or show as not installed

docker --version

systemctl status docker

If these commands show Docker is still present, you may need to find and remove any remaining binaries:

# Find any Docker-related files that may remain in the system

sudo find /usr -name "*docker*"

sudo find /bin -name "*docker*"

sudo find /usr/local/bin -name "*docker*"

In a server environment, there are usually follow-up steps after uninstalling Docker. If you plan to reinstall a new version, you can start the new installation process now. If your server is a long-running production machine, it is recommended to consider a reboot to ensure that all Docker-related kernel modules and network interfaces are completely removed:

sudo reboot

After rebooting, check that the network configuration has returned to normal, especially that the `docker0` bridge created by Docker should be gone. If you need to prepare for future containerization, you may need to install an alternative container runtime, such as Podman, or use containerd directly.

Finally, it's worth noting some precautions during the uninstallation process. On a server used for team collaboration, always notify all relevant personnel before uninstalling, as it may affect the services of others. If the server contains important data mounted using Docker volumes, ensure that this data has been backed up to a secure location. For servers configured with Docker Swarm or Kubernetes nodes, remove them from the cluster before uninstalling to avoid disrupting the cluster state. If Docker is configured for remote API access, the relevant ports may remain open after uninstallation; it is recommended to check firewall rules.

In summary, uninstalling Docker on an Ubuntu server is a systematic process involving four main stages: service stopping, package removal, data cleanup, and state verification. Unlike desktop environments, server uninstallation requires a higher degree of thoroughness and careful consideration of subsequent impacts.

DNS Luna
DNS Amy
DNS Becky
DNS NOC
Title
Email Address
Type
Information
Code
Submit