Thanks to Docker, the developers can build, test, and deploy the software applications in any environment. You can think of Docker as a tool that works like a VM, only that it doesn’t stress the host system’s resources. Sometimes, you may wish to uninstall Docker on your Ubuntu 22.04. In such a case, you need a safe method to uninstall Docker and all its containers. We will cover a step-by-step process to cleanly uninstall Docker on Ubuntu 22.04.
Uninstall Docker on Ubuntu 22.04
We will uninstall Docker and its containers in different steps.
1. Confirm the Docker Packages
The first step is to list all the available Docker packages on your Ubuntu 22.04. You can use the dpkg command to list the installed packages or check the Docker version:
2. Delete the Docker Images
Deleting the Docker packages doesn’t delete the images that you created. Start by checking the available docker images with the following command:
Delete the available images by executing the following command:
The command that we executed removes all the images to clear the space that is previously occupied by the Docker images on your system.
If we try listing the images again, no Docker image is available on the system. This means that we managed to remove them all.
3. Delete the Docker Containers
When working with Docker, you must create different containers. We also need to delete them before uninstalling the Docker package. List the available containers with the ps -a command.
You can delete each container independently, but that would take time, especially if you have multiple containers. A better approach is to delete all the available containers using the rm command.
All the container IDs of the deleted containers are displayed after you execute the rm command. Verify that the containers are deleted by checking the available containers.
4. Delete the Docker Volumes
If you also have the Docker volumes that you created, the rm command will help you delete them. List the available volumes. Then, specify the names of the volumes that you want to delete, as presented in the following:
$ docker volume rm <volume-name>
Your Docker volumes are deleted, and the space is available to the host system.
5. Delete the Docker Networks
Check if you have any networks that you created using the ls command. Here, we have the linuxhint network. To delete the network, use the rm command.
$ docker network rm linuxhint
Alternatively, you can delete all the networks using the prune command. Here’s an example where we delete the “neww” network:
At this point, you are ready to remove the Docker package from your Ubuntu 22.04.
6. Uninstall the Docker Package
After identifying the Docker packages on your system, delete them by running the following command:
Here, we remove the docker.io package. Note that we opted to delete the Docker packages last since uninstalling the Docker packages won’t remove your images, containers, volumes, etc.
Note that the Docker directory is not removed even after uninstalling the package.
At the last line, you will notice the message that your /etc/docker and /var/lib/docker/ directories are still available on your system.
We can verify that the Docker files still exist on our system.
Remove these directories from your system with the following command:
Also, delete the Docker group that you created when installing the Docker.
Lastly, remove the Docker socket from your system.
Docker is great for deploying and managing applications. However, when you don’t need to have the Docker in your system, you can uninstall it and all the created containers, images, networks, etc. This guide presented all the steps that you should follow to uninstall the Docker software and all its containers on Ubuntu 22.04.