How to Completely Uninstall Docker from Ubuntu

This article explains how to uninstall or remove Docker completely from Ubuntu Linux. It will show you how to delete Docker images, containers, configuration files, volumes, and packages.

Docker is a platform that allows developers to create, deploy, and run applications in containers easily. Containers are lightweight, portable, and self-sufficient environments containing all the necessary libraries and dependencies to run an application.

When you no longer need Docker on Ubuntu, you can uninstall the packages, but doing so won’t remove other images, containers, and configuration files. To properly remove Docker and related files, use the steps below.

There could be several reasons why someone may want to remove Docker from Ubuntu Linux. First, if they installed Docker to test it out or for a specific project and no longer need it, they may want to remove it to free up space on your system.

Sometimes, Docker may conflict with other software on your system, causing issues. You may want to remove Docker to resolve the conflict in such cases. If you want to upgrade to a new version of Docker, removing the previous version first is recommended.

Delete Docker images, containers, and volumes

As mentioned above, users can delete Docker images, containers, volumes, and other configuration files before uninstalling Docker.

Here’s how to do that.

First, stop the Docker containers that are running, then remove them.

Run the command below to do that.

docker stop $(docker ps -a -q)

The command will list all the Docker containers and stop them. Once they are stopped, run the command below to remove them.

docker rm $(docker ps -a -q)

Next, remove Docker images. Run the command below to do that. The command lists all the active and intermediate images and removes them from the system.

docker rmi $(docker images -a -q)

Next, remove all Docker networks. The command will remove Docker custom networks from the system.

docker network prune

Next, remove all cache and volumes. You can do that using the command below.

docker system prune -a

The command will perform the following actions:

  • Remove all stopped containers
  • Remove networks that are not used by at least one container
  • Remove Images without at least one container associated with them
  • Remove build cache

Confirm when prompted.

Finally, uninstall Docker packages and delete leftover files. You can do that by running the commands below.

sudo apt remove docker-* --auto-remove
sudo rm -rf /var/lib/docker
sudo groupdel docker
sudo rm -rf /var/run/docker.sock
sudo rm -rf /usr/local/bin/docker-compose && sudo rm -rf /etc/docker && sudo rm -rf ~/.docker

That should do it!

Conclusion:

  • The guide provided comprehensive instructions on how to uninstall Docker from Ubuntu Linux, covering the deletion of images, containers, volumes, and packages and removing leftover files and configurations.
  • Following these steps will effectively free up space on the system and ensure the complete removal of Docker and its associated components.
  • Users are encouraged to share feedback or additional insights through the comments section for future reference and improvement.

Frequently Asked Questions

How do I completely uninstall Docker from Ubuntu?

To completely uninstall Docker from Ubuntu, you need to stop and remove all containers, images, and volumes. Then, run the command 'sudo apt remove docker-* –auto-remove' followed by commands to delete leftover files and configurations.

What commands do I need to delete Docker containers and images?

You can delete Docker containers using 'docker rm $(docker ps -a -q)' and remove images with 'docker rmi $(docker images -a -q)'. Make sure to stop the containers first using 'docker stop $(docker ps -a -q)'.

Why would I want to uninstall Docker from my Ubuntu system?

You might want to uninstall Docker if you no longer need it for testing or specific projects, to free up space, or to resolve conflicts with other software. Additionally, if you're upgrading to a new version, it's recommended to remove the previous version first.

What should I do with Docker volumes before uninstalling?

Before uninstalling Docker, you should remove all volumes to free up space. You can do this by running the command 'docker system prune -a', which will also remove stopped containers and unused images.

Are there any leftover files after uninstalling Docker?

Yes, after uninstalling Docker, there may be leftover files and configurations. To remove these, you can run commands like 'sudo rm -rf /var/lib/docker' and 'sudo rm -rf /etc/docker' to clean up completely.

Categories:

Leave a Reply

Your email address will not be published. Required fields are marked *