Home > Software > How to Completely Remove Docker from Ubuntu

How to Completely Remove Docker from Ubuntu

Anastasios Antoniadis

Share on X (Twitter) Share on Facebook Share on Pinterest Share on LinkedInDocker is a widely used platform that allows developers to package and distribute applications easily. However, there might be instances when you need to remove Docker from an Ubuntu system, be it for troubleshooting, freeing up system resources, or installing a different version. …

Docker (1)

Docker is a widely used platform that allows developers to package and distribute applications easily. However, there might be instances when you need to remove Docker from an Ubuntu system, be it for troubleshooting, freeing up system resources, or installing a different version. This article offers a comprehensive guide on how to completely remove Docker, Docker Engine, Docker Compose, and other related dependencies from your Ubuntu system.

Prerequisites

Before proceeding, ensure that you are logged in as a user with sudo privileges to perform system operations.

Step 1: Uninstall Docker Packages

To begin with, if you want to completely remove Docker from your system, you need to uninstall the Docker packages that were installed on your system earlier. It is possible that Docker was installed in different ways, such as through Ubuntu’s repositories, Docker’s official repositories, or convenience scripts. However, in this guide, we’ll only cover the removal process for Docker installations that were performed using Docker’s official repositories.

Remove Docker Engine, CLI, and Containerd packages

To remove the Docker Engine, CLI, and Containerd packages, execute the following command:

sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin

This command will remove Docker and its associated packages but will leave your images, containers, volumes, or customized configuration files on your host untouched.

Step 2: Remove Docker Images, Containers, and Volumes

If you wish to remove all images, containers, and volumes, you should manually delete the Docker data directory. By default, Docker stores its data in /var/lib/docker. You can remove it using the following command:

sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerd

Warning: This action is irreversible. Ensure you have backups of any important data before proceeding.

Step 3: Remove Docker Network

Docker creates a default network bridge on installation. If you want to remove this network, you should first inspect if any network bridges are left:

ifconfig

Or for newer versions of Ubuntu:

ip addr

Look for networks named like docker0 or similar. If found, you can delete it using the ip command:

sudo ip link delete docker0

Replace docker0 with the name of the network bridge you wish to remove.

Step 4: Remove Docker Dependencies

After uninstalling Docker and removing its data, you may also want to uninstall the dependencies that were installed with Docker:

sudo apt-get autoremove -y

This command removes packages that were automatically installed to satisfy dependencies for Docker but are now no longer needed.

Step 5: Remove Docker’s Repository

If you added Docker’s repository to install Docker, you might want to remove it from your system’s software sources:

  1. Open the /etc/apt/sources.list.d directory.
  2. Look for the Docker list file, usually named docker.list.
  3. Remove the file:
sudo rm /etc/apt/sources.list.d/docker.list

Step 6: Refresh the Package Database

After removing Docker and its repository, update your package database:

sudo apt-get update

This command refreshes your package manager’s database, ensuring it no longer searches for packages from the Docker repository.

Conclusion

If you want to remove Docker from your Ubuntu system, simply uninstalling the packages won’t be enough. You’ll need to clean up data directories, remove Docker networks, and dependencies as well. Following the steps mentioned in this guide can help you completely remove Docker and its components from your system. Whether you want to reinstall Docker from scratch or just free up system resources, this guide provides a detailed walkthrough of the process.

Anastasios Antoniadis
Follow me
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x