How to Uninstall Docker on Ubuntu
To uninstall Docker on Ubuntu, purge its packages with apt, and if you want the images, containers and volumes gone as well, delete /var/lib/docker and /var/lib/containerd. Purging the packages on its own leaves all of that data behind. Below is the complete removal for Docker's official docker-ce packages and for Ubuntu's docker.io, along with the repository, the docker group and the other leftovers.
Read this first: deleting /var/lib/docker wipes out every container, image and volume on the server, databases kept in volumes included. Back up anything you still need beforehand (the last section shows how).
Step 1: Check how Docker was installed
dpkg -l | grep -Ei 'docker|containerd'
snap list docker 2>/dev/null
- Seeing
docker-ce,docker-ce-cliandcontainerd.io? Your Docker came from Docker's own repository; carry on with step 2a. - Seeing
docker.io? It was Ubuntu's package; jump to step 2b. - Seeing a
dockersnap? It was a snap install; jump to step 2c.
Step 2a: Uninstall Docker on Ubuntu (docker-ce packages)
First stop the services, then purge the packages. The package names below come from Docker's uninstall instructions:
sudo systemctl stop docker.socket docker.service containerd.service
sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
sudo apt autoremove
purge deletes the packages together with their system configuration files, and autoremove clears out dependencies that were only there for Docker. How remove, purge and autoremove differ is explained in our guide to uninstalling packages in Ubuntu.
Step 2b: Uninstall docker.io (Ubuntu's package)
sudo systemctl stop docker.socket docker.service
sudo apt purge docker.io docker-compose docker-compose-v2 docker-buildx docker-doc podman-docker containerd runc
sudo apt autoremove
Any package in that list that isn't installed is simply skipped.
Step 2c: Uninstall the Docker snap
sudo snap remove --purge docker
With --purge, snap also throws away the snapshot of the snap's data that it would otherwise keep. The snap keeps its data in its own directories, so you can skip step 3.
Step 3: Delete images, containers and volumes
Purging the packages leaves Docker's data in place: according to Docker's documentation, images, containers, volumes and custom configuration files aren't removed automatically. See how much space they take:
sudo du -sh /var/lib/docker /var/lib/containerd
Then delete them:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
If you relocated Docker's data with data-root in daemon.json, delete that directory instead.
From Docker Engine 29, image data is kept in /var/lib/containerd, which is why the commands above delete both directories. A custom data-root leaves containerd's storage where it was, so look in /var/lib/containerd even if you moved Docker's data elsewhere.
Step 4: Remove the repository and key
For an install from Docker's repository, delete its source file and signing key so that apt update no longer checks it:
sudo rm -f /etc/apt/sources.list.d/docker.sources /etc/apt/sources.list.d/docker.list
sudo rm -f /etc/apt/keyrings/docker.asc /etc/apt/keyrings/docker.gpg
sudo apt update
Depending on its age, an install used either docker.list with docker.gpg or docker.sources with docker.asc. Running the commands above deals with both, as -f stays silent about files that aren't there.
Step 5: Clean up the leftovers
None of this is needed to remove Docker itself, but it leaves the server as if Docker had never been on it:
sudo rm -rf /etc/docker # daemon.json and certificates
rm -rf ~/.docker # your CLI config and registry logins
sudo groupdel docker # the docker group
Registry logins saved in ~/.docker/config.json may contain credentials, so remove that file before handing the server to someone else. Do the ~/.docker step for every user who used Docker.
For Docker in rootless mode, run dockerd-rootless-setuptool.sh uninstall as that user before purging the packages, then delete ~/.local/share/docker.
Step 6: Check that Docker is gone
which docker
docker --version
systemctl status docker
Expect no output from which, "command not found" from docker --version, and a message from systemd that the unit could not be found.
If docker still works, there is probably a second installation:
ls -l $(command -v docker)
snap list | grep docker
A binary under /usr/local/bin usually points to a manual install or an old install script.
Check the firewall too. Docker creates iptables chains of its own, and they normally vanish with the service. Should DOCKER chains still show up in sudo iptables -L, a reboot removes them.
Back up before you uninstall
To hang on to a volume's data, archive it before Docker is gone:
docker volume ls
docker run --rm -v pgdata:/data -v "$PWD":/backup alpine \
tar czf /backup/pgdata.tar.gz -C /data .
An image you want to keep can be exported with docker save -o myapp.tar myapp:1.0, then copied elsewhere. Moving big files between servers is what our guide to syncing directories with rsync is about.
Reinstalling Docker
Starting over on a fresh VPS can be faster than cleaning up an old one. If the goal is to repair a broken install, or to switch from docker.io to Docker's official packages, continue with our guide to installing Docker on Ubuntu. And if all you wanted was disk space, uninstalling may be unnecessary: removing unused Docker images plus docker system prune usually win most of it back.
Frequently asked questions
Does uninstalling Docker delete my containers and images?
No. apt purge takes away the programs, while images, containers and volumes remain in /var/lib/docker until you delete that folder yourself.
What is the difference between apt remove and apt purge for Docker?
apt remove leaves the packages' configuration files in place, whereas apt purge deletes them as well. /var/lib/docker is untouched by both.
How do I uninstall only Docker Compose?
The plugin goes with sudo apt purge docker-compose-plugin. The legacy v1 tool is a single binary, normally /usr/local/bin/docker-compose; delete it.
How do I uninstall Docker Desktop on Ubuntu?
sudo apt purge docker-desktop removes it, and after that you can delete ~/.docker/desktop. Bear in mind Docker Desktop is its own product, not the Docker Engine that runs on servers.
Is it safe to delete /var/lib/docker?
Only once the Docker service is stopped, and only if no container, image or volume on the server matters to you any more. Deleting it while Docker is running can corrupt its state, and there is no way to get the data back afterwards.
How do I remove Docker from Ubuntu but keep my data?
Run the purge from step 2 but not the deletion in step 3. Your images, containers and volumes then stay put in /var/lib/docker and /var/lib/containerd, where a future Docker install will normally find them again.
Was this article helpful?
Written by Julius · Product Manager