How to Uninstall Docker on Ubuntu? Step-by-Step Guide

August 19th, 2024
How to Uninstall Docker on Ubuntu? Step-by-Step Guide

Knowing how to uninstall Docker safely is also as important as knowing how to install Docker on your machine. Uninstalling Docker is inevitable in cases where containers are corrupt or the installation was corrupt to a point where some Docker features do not function properly. There are certain steps that you have to follow when uninstalling Docker to prevent scenarios where Docker is not completely uninstalled or losing data.

There are several circumstances where it is crucial to uninstall Docker such as:

  • Uninstalling Docker to fix issues caused by corrupt and unsuccessful installation. Completely uninstalling Docker removes all the issues that were caused by insecure and privileged containers.
  • Uninstalling Docker to perform system cleanup and reclaim disk space taken by unwanted containers and volumes.
  • Uninstalling Docker to improve and optimize system performance. Sometimes your system's performance issues can be caused by Docker, especially when containers overconsume system resources.
  • Uninstalling Docker deletes configurations enabling you to reinstall Docker and set Docker to default settings.

In this article, you will learn how to uninstall Docker on Ubuntu. In addition, you will learn the necessary steps that you should take before uninstalling Docker in order to shut down Docker processes safely.

Prerequisites

You need to have installed Docker on Ubuntu.

Ready to supercharge your Docker infrastructure? Scale effortlessly and enjoy flexible storage with Cherry Servers bare metal or virtual servers. Eliminate infrastructure headaches with free 24/7 technical support, pay-as-you-go pricing, and global availability.

How to remove Docker containers safely

If safety measures are not taken into consideration, uninstalling Docker will result in data loss. Uninstalling Docker automatically deletes filesystems and volumes. It is important to ensure that there is external storage that backs up all crucial Docker data before uninstalling Docker. Below are the steps you should take before uninstalling Docker.

1. Listing containers using Docker ps command to analyze container status

Before you uninstall Docker, get an overview of all the containers by listing them all using the docker ps command. This can help you notice containers and data that has to be backed up before uninstalling docker. Uninstalling Docker has to be a careful and cautious process.

2. Properly stopping containers before uninstalling Docker

Some containers depend on each other, uninstalling Docker without stopping processes can cause issues for the remaining container. Stopping a Docker container ensures that all running processes are shutdown properly.

Before you uninstall Docker, stop all running containers using the docker stop command. This command stops a specified running container. You can also state how long Docker should wait before killing the container using the --time flag. For example, the command below stops the specified container in 30 seconds.

docker stop -t 30 [container name or ID]

3. Removing Docker containers

The docker rm command is used to remove containers, you can also use this command as a flag when using the docker run command to automate the task of removing exiting containers. If the container is failing to get removed, you should add the --force flag which will force the removal of the container. To remove a specific volume from the container add the --volume flag followed by the name of the volume. If you want to remove a container link add the --link flag.

Links are used to enable communication between the container and host.

docker rm [container name or ID]

4. Removing unused images and volumes using Docker system prune

Fortunately, Docker offers an easy way to remove unused images and volumes. The docker system prune removes unused images using the --all flag and --volume for removing unused volumes. To force the removal use the --force flag.

docker system prune --volumes

5. Backing up and saving Docker data

Don’t forget to save the images that you built, you will need them the next time you reinstall Docker. You can save Docker images you built to a tar file using the docker save command and store them locally or remotely. The command will require you to specify the name of the image you wanna save.

docker save [image] > [filename].tar

How to uninstall Docker on Ubuntu

  1. Start by stopping Docker services immediately using systemctl:
sudo systemctl stop docker
  1. Next, use the purge command to remove the Docker package: “docker-ce”. The -y option will optically say yes to all prompts that might appear during the purging process:
sudo apt-get purge docker-ce -y

You will get the following output that shows the docker-ce package being removed:

Removing Docker package

  1. Use the following command to automatically remove Docker configuration files:
sudo apt-get autoremove --purge docker-ce -y
  1. Now remove the Docker storage files on the /etc/docker directory:
rm -rf /etc/docker
  1. Use the following command to remove the Docker daemon storage location:
rm -rf /var/lib/docker
  1. To test if Docker has been uninstalled completely use the following command to check the Docker status:
sudo systemctl status docker

You will get the following output if the uninstallation process was a success:

Unit docker.service could not be found.

Conclusion

In this guide, you have learned how to uninstall Docker on Ubuntu. In addition, you have learned the safety precaution tasks you have to execute before uninstalling Docker to ensure that no data loss occurs. Uninstalling Docker will give you an opportunity to reinstall Docker successfully and avoid any issues that can cause Docker features to function abnormally.

Boemo is a software developer specializing in DevOps technical writing. He has more than 3 years of experience in DevOps technical writing. He has written detailed tutorials on DataOps, Kubernetes security tools, and Android video chat implementation using Agora. He is an expert in authoring Linux, Docker, Kubernetes and Android development tutorials. He currently works as a freelance technical writer and resides in Gaborone, Botswana. In his previous role as a freelance DevOps writer at Draft.dev he reviewed developer tools such as Cast.ai, Shipa, and Kubecost. After gaining abundant knowledge on how these tools work, he wrote articles that compare developer tools and show developers the best tools they should use for different DevOps cost analysis use cases.

Start Building Now

Deploy your new Cloud VPS server in 5 minutes starting from $5.83 / month.

We use cookies to ensure seamless user experience for our website. Required cookies - technical, functional and analytical - are set automatically. Please accept the use of targeted cookies to ensure the best marketing experience for your user journey. You may revoke your consent at any time through our Cookie Policy.
build: b0376f5bd.760