Table of Contents
Uninstalling Docker on Ubuntu
Docker is one of the well-known containerization tools which is widely used in most organizations. Docker helps the developer build, test and deploy their application seamlessly across various environments. It is one of the best offerings and an important tool in the area of DevOps.
In a few cases, you might not be willing to use docker and you may want to uninstall Docker from your system. How do we do that?
In this article, let us understand how to uninstall Docker on Ubuntu OS. Let us get started.
Uninstall Docker Engine
Step-1: List all the available packages
You must know the available docker packages before deleting them. Let us list all the available docker packages on our system with the command
$ dpkg -l | grep -i docker
Output
docker.io 20.10.12-0ubuntu4 amd64 Linux container runtime
Step-2: Delete the Docker packages
Upon identifying the docker packages, now go ahead and delete them using the below command
$ sudo apt-get purge -y docker.io
You will notice that the docker packages will be deleted upon execution of the command.
Output
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
bridge-utils containerd pigz runc systemd-hwe-hwdb ubuntu-fan
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
docker.io*
0 upgraded, 0 newly installed, 1 to remove and 104 not upgraded.
After this operation, 158 MB disk space will be freed.
(Reading database ... 208231 files and directories currently installed.)
Removing docker.io (20.10.12-0ubuntu4) ...
'/usr/share/docker.io/contrib/nuke-graph-directory.sh' -> '/var/lib/docker/nuke-graph-directory.sh'
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
Processing triggers for man-db (2.10.2-1) ...
(Reading database ... 208025 files and directories currently installed.)
Purging configuration files for docker.io (20.10.12-0ubuntu4) ...
Nuking /var/lib/docker ...
(if this is wrong, press Ctrl+C NOW!)
+ sleep 10
+ rm -rf /var/lib/docker/buildkit /var/lib/docker/containers /var/lib/docker/image /var/lib/docker/network /var/lib/docker/nuke-graph-directory.sh /var/lib/docker/overlay2 /var/lib/docker/plugins /var/lib/docker/runtimes /var/lib/docker/swarm /var/lib/docker/tmp /var/lib/docker/trust /var/lib/docker/volumes
dpkg: warning: while removing docker.io, directory '/etc/docker' not empty so not removed
Uninstalling docker will not delete all the docker stuff. Hence, you must remove the docker images, containers, volumes, and other configurations that you created since they are not removed automatically.
In this section let us understand how to remove docker images, containers, volumes, and networks.
Step-3: Delete Docker Images
Remove docker images
$ docker rmi $(docker images -a -q)
Step-4: Delete Docker Containers
Remove all exited docker containers
$ docker rm $(docker ps -a -f status=exited -q)
Remove running docker containers by first stopping them and later removing them
$ docker stop $(docker ps -a -q) $ docker rm $(docker ps -a -q)
Step-5: Delete Docker Volumes
Remove specific containers using container ID or container name
$ docker rm ID_or_Name ID_or_Name
Remove all docker volumes
$ docker volume prune
Step-6: Delete Docker Networks
Remove all docker networks
$ docker network prune
Step-7: Deleting the remaining docker files
You can execute the commands to completely remove docker and its related files from your system.
All the docker files will be in the /var/lib/docker
path so you have to remove the folder.
$ sudo rm -rf /var/lib/docker /etc/docker
Delete the docker group that you have created in order to run the docker as non-root user or without sudo
$ sudo groupdel docker
Delete the docker socket using the command below
$ sudo rm -rf /var/run/docker.sock
In case you have docker-compose installed, delete that using the command below
$ sudo rm -rf /usr/local/bin/docker-compose
$ sudo rm -rf /etc/docker
$ sudo rm -rf ~/.docker
With this, the uninstallation of docker will be successful. You can verify if the docker has been uninstalled by typing $ docker
command
Upon successful uninstallation of docker, you will see the below output.
Output
bash: /usr/bin/docker: No such file or directory
This confirms that Docker is no longer available in your system. In case you want to use Docker, you have to re-install it on your system.
Summary
The article guides you about how to uninstall docker and also how to delete all the docker images, containers, etc. Hope this article helped you understand the topic. I suggest you try out the steps explained in this article and in case you have any queries or doubts, please feel free to reach out to us and we will respond at the earliest.
Thanks for reading the article. happy learning!!
References
https://docs.docker.com/engine/install/ubuntu/#prerequisites
https://askubuntu.com/questions/935569/how-to-completely-uninstall-docker