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.
Step-1: Removing Docker Images, Containers, Volumes, and Configurations
Docker utilizes images as blueprints for applications, containers as running instances, volumes for persistent storage, and configurations to customize behaviors.
Remove docker images
docker rmi $(docker images -a -q)
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)
Remove all docker networks
docker network prune
The docker system prune -a
command cleans up unused Docker components, freeing space but also potentially resulting in data loss. Care should be taken before executing cleanup commands to ensure critical data is backed up.
docker system prune -a
The command docker system prune -a is a powerful tool that removes:
- All stopped containers
- All networks not used by at least one container
- All volumes not used by at least one container
- All images without at least one container associated with them
- All build cache
Step-2: Delete the Docker 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
Sample Output:
root@host01:~$ dpkg -l | grep -i docker
ii docker-buildx-plugin 0.10.4-1~ubuntu.22.04~jammy amd64 Docker Buildx cli plugin.
ii docker-ce 5:24.0.1-1~ubuntu.22.04~jammy amd64 Docker: the open-source application container engine
ii docker-ce-cli 5:24.0.1-1~ubuntu.22.04~jammy amd64 Docker CLI: the open-source application container engine
ii docker-ce-rootless-extras 5:24.0.1-1~ubuntu.22.04~jammy amd64 Rootless support for Docker.
ii docker-compose 1.29.2-1 all define and run multi-container Docker applications with YAML
ii docker-compose-plugin 2.18.1-1~ubuntu.22.04~jammy amd64 Docker Compose (V2) plugin for the Docker CLI.
ii python3-docker 5.0.3-1 all Python 3 wrapper to access docker.io's control socket
ii python3-dockerpty 0.4.1-2 all Pseudo-tty handler for docker Python client (Python 3.x)
Upon identifying the docker packages, now go ahead and delete them using the below command
sudo apt-get purge docker-ce docker-ce-cli containerd.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: 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.
Step-4: Removing Docker User Group
Docker often creates a user group named docker
. Provide a command to delete it:
sudo groupdel docker
Step-5: Cleaning Up Unused Packages
Recommend running:
sudo apt-get autoremove
This command removes packages that were installed as dependencies and are no longer used and that's it, you have successfully removed docker from 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.
For further information you can refer:
https://docs.docker.com/engine/install/ubuntu/#prerequisites
https://askubuntu.com/questions/935569/how-to-completely-uninstall-docker
Still works in 2025
nice job