Docker can be defined as the software library that helps users to develop, run, and manage applications. It is a lightweight container that automates the deployment of applications on Linux, allowing the applications to run efficiently under different environments. It is highly recommended to uninstall the older Docker before updating to a new one because the update often fails, which could result in data loss. A simple uninstallation of Docker may leave a few configuration files behind that can cause conflicts with the newer version.
This article explains how users can completely uninstall docker on Linux.
- How to Uninstall Docker?
- Delete Docker Packages
- Delete Docker Images
- Delete Docker Containers
- Delete Docker Volumes
- Delete Other Docker Files
How to Uninstall Docker on Linux?
To completely uninstall, including all files of Docker, a few commands are to be executed:
Step 1: Delete Docker Packages
First, identify the available docker packages before getting rid of them. To list the docker packages, use this command:
$ dpkg -l | grep -i docker #For Debian/Ubuntu-based $ sudo dnf list installed | grep docker #For Fedora/CentOS $ sudo yum list --installed | grep docker #For Arch Linux
The above indicates that “docker.io” is the current docker package installed on the system. Let’s remove it:
$ sudo apt purge -y docker.io
As highlighted (using arrows) in the above image, there is an indication that some packages were not removed during the uninstallation process.
Step 2: Delete Docker Images
A docker image is a set of instructions to create and run a container on the docker platform and to uninstall them, execute this command:
$ docker rmi $(docker images -a -q)
In some cases, such as above, the docker images are already removed, and it will remove all of them if found on the system:
Step 3: Delete Docker Containers
A docker container can be defined as the executable package of the software, which is compiled so that the container has everything required to run it. To remove them, execute this command:
$ docker rm $(docker ps -a -f status=exited -q)
The docker containers were already deleted, and the above command will remove any of them if found on the system.
Step 4: Delete Docker Volumes
Docker volumes are pretty valuable tools for containers as they are mounted on the system to preserve the data generated by the docker containers. Removing them requires the execution of this command:
$ docker volume prune
The docker volumes are removed from this system, and the above command will remove any docker volumes (if found on the system.)
Delete Other Docker Files
After the uninstallation of all components of docker, and there are a few files left that can be deleted by executing the following command:
$ sudo rm -rf /var/lib/docker /etc/docker
The above command removes the “/etc/docker” folder with all its files from the system.
Step 5: Delete Docker Group
The docker group allows non-root users to access docker without root-level privileges. To delete it, use this command:
$ sudo groupdel docker
After deleting the last entity, i.e., docker groups, it is conclusive that docker is entirely uninstalled from the system. It can be confirmed by launching the docker:
The output shows that the docker has been completely uninstalled.
To uninstall docker is a simple process and can be done using a single command, but a few things are left behind, creating issues like being stuck at upgrading to the latest version. So, we have to remove all files one by one.
This guide has illustrated the process of eliminating all docker components from the system.