How to uninstall / remove docker completely form ubuntu linux

Today I am writing how to completely remove / uninstall the docker and it's components properly from my ubuntu linux vm hosted on proxmox. I will run all the commands as root, if you don't have root permission, please switch to root or sudoers user for continue without any errors.
 


First I need to stop any existing container if running:

  • docker stop [container name / ID]
    • This command stops the container with the specific name or docker container IDs
  • docker rm  [container name / ID]
    • After stopping the container I need to rm the container one by one or I can remove multiple container at a time

After stopping and removal of the containers I am going to remove the volumes where all the containers and docker images stored.
  • docker system prune --volumes
    • Will remove all the image files and data related to docker containers
Now I am going to stop the docker and after that will run the commands to remove all docker installed files on the system.
  • sudo systemctl stop docker
    • This will stop the docker services on the system
  • sudo apt-get purge docker-ce -y
    • This command will remove all docker application
  • sudo apt-get autoremove --purge docker-ce -y
    • Will purge docker completely 
  • sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
    • And this command is as optional or you can use as alternatives of above. During the run of this command you need to press y to accept the uninstallation process


And finally I will remove all the leftover folders created for docker on the /etc/ and /var/lib folder.
  • rm -rf /etc/docker
  • rm -rf /var/lib/docker



Finally I need to check the docker with status commands
  • sudo systemctl status docker
    • If you see: "Unit docker.service could not be found - means you have successfully uninstalled / removed docker and it's services completely from your ubuntu linux system.


Comments