2

I have installed Docker using Docker's official apt repo.

My question is, if I uninstall it using sudo apt-get remove docker docker-engine docker.io containerd runc. Will Docker containers and images will also be deleted?

Or should I run a docker system prune explicitly before uninstall?

Artur Meinild
  • 26,018
  • Keep in mind that docker system prune does not delete everything either if there are running containers. As those containers and their images and the attached network and volumes will be kept. – Dan Jun 03 '22 at 09:26

2 Answers2

1

All the data is in /var/lib/docker. However, this data will not be removed when uninstalling the packages.

So it can be removed with:

sudo rm -rf /var/lib/docker
Artur Meinild
  • 26,018
1

To piggyback on @ArturMeinild answer, I'd like to add a general explanation from Apt's perspective, which can help explain what data would not be deleted, as it's always safe to assume that the answer would be no.

In general, apt remove only removes files installed by the deb package. It does not touch configuration files (which are usually under /etc) nor user-generated files*.

The other option is to use apt prune, but generally, it just deletes what apt remove deletes, plus the configuration under /etc. But it also ignores user-generated files.

* User-generated files don't necessarily mean the user needs to create them manually, but they can also be files that are generated by the binary (such as containers and images in this case)

Dan
  • 13,119