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, except that it doesn’t burden the host system’s resources. Sometimes you may want to uninstall Docker on your Ubuntu 22.04. In such a case, you need a safe way 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. Approve the Docker packages
The first step is to list all 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 will not delete the images you build. First, check the available Docker images with the following command:
Delete the available images by running the following command:
The command we run removes all images to free up the space previously occupied by the Docker images on your system.
When we try to list the images again, there is no docker image available on the system. That means we managed to remove them all.
3. Delete the Docker containers
When working with Docker, you need to 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 individually, but that would take some time, especially if you have multiple containers. A better approach is to delete all available containers using the rm command.
All container IDs of the deleted containers are displayed after you run the rm command. Make sure the containers have been deleted by checking the available containers.
4. Delete the Docker volumes
If you also have the docker volumes you created, the rm command will help you delete them. List the available volumes. Then provide the names of the volumes you want to delete as shown below:
$ docker volume rm <volume name>
Your Docker volumes will be deleted and the storage space will be available to the host system.
5. Delete the Docker networks
Check if you have networks that you created with the ls command. Here we have the Linuxhint network. To delete the network, use the rm command.
$ docker network rm Linux hint
Alternatively, you can delete all networks using the prune command. Here is a example where we delete the network “neww”:
At this point you can 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 have chosen to delete the Docker packages last, since uninstalling the Docker packages will not remove your images, containers, volumes, etc.
Note that the Docker directory is not removed even after uninstalling the package.
On 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 Docker.
Lastly, remove the Docker socket from your system.
Docker is great for deploying and managing applications. However, if you don’t need Docker in your system, you can uninstall it and all created containers, images, networks, etc. Containers on Ubuntu 22.04.