
Docker allows you to containerize your applications, making it rather easy to distribute the entire software stack needed for applications to run. Have you decided you no longer have a need for docker on your Ubuntu system and would like to remove it completely? If so this post is for you, as we will go through how to completely uninstall docker step by step.
Before You Start
- Make sure that you want to remove Docker and that you or another user aren’t using any services inside of Docker.
- Ensure you have the necessary permissions to uninstall Docker, you will need either root access or sudo permissions.
- Back up any data or configurations even if there is a slight chance you may need the data in the future.
Stop All Containers and Data
First, run docker commands to stop any currently active Docker containers.
sudo docker stop $(sudo docker ps -q)
In case you have containers set to restart we will force remove them as the cleanup command below won’t.
sudo docker rm -f $(docker ps -aq)
Next let’s use docker’s built-in cleanup command to remove all stopped docker containers, unused networks, docker images, and docker files.
sudo docker system prune --volumes
Run the following command to check if there are any containers left on your system. You should see an empty output if all containers have been successfully removed.
sudo docker ps -a
Uninstallation
Run the following commands to uninstall docker packages like docker itself, compose, and even docker desktop from your system.
sudo apt-get remove 'docker*'
To ensure that any configuration files associated with Docker packages are also removed, use the purge command:
sudo apt-get purge 'docker*'
Clean Up
After removing the Docker packages, you should delete the data directory where images, containers, and volumes are stored. This ensures that no residual Docker data remains.
sudo rm -rf /var/lib/docker
Since Docker relies on containerd for runtime management, it’s also a good idea to clear out its data directory.
sudo rm -rf /var/lib/containerd
Note: If you used a different location for storing data or edited configuration files those likely haven’t been removed. You will need to address those individually.
Removing Docker GPG Key and Repository
Finally, remove any APT source lists and GPG keys associated with Docker that were added for installation from the official repository. This ensures you have no leftover configuration that might cause issues in the future.
sudo rm /etc/apt/sources.list.d/docker.list
sudo rm /etc/apt/keyrings/docker.asc
Verifying the Uninstallation
To make sure there are no more related docker processes running, run the following command:
ps a | grep docker
You can check if any Docker-related packages are still installed by running:
dpkg -l | grep -E 'docker'
Note: If you see a docker-related package still running or installed, try rebooting and see if that solves it.
Conclusion
In this post, we covered the steps to completely remove Docker from your Ubuntu-based system. From prerequisites to stopping all containers and removing their data, to uninstalling docker, cleanup, removing GPG keys, and verification. You have now finished as well as other docker packages like uninstalling docker desktop uninstalling Docker. If you decide you later want to reinstall Docker, you can run the same commands as you used when you installed it before. Consider reinstalling Docker Engine using the official installation instructions.
Looking For More
Done reading and looking for more, why not check these out?

Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.
Leave a Reply