Skip to content

How to uninstall Docker completely on Ubuntu and Debian ​

Removing the Docker package is one command, but it leaves a lot behind: every image, container and volume, the apt repository, the docker group and sometimes a second copy of Docker installed another way. This guide removes all of it step by step on Ubuntu and Debian, so you end up with either a clean server or a clean base for a fresh install.

Commands use sudo. If you are logged in as root, leave it out.

Step 1. Find out how Docker was installed ​

There are several ways Docker ends up on a server, and each one is removed differently. Check all of them, since more than one can be present at the same time:

bash
dpkg -l | grep -Ei 'docker|containerd|runc'
snap list 2>/dev/null | grep -i docker
which -a docker docker-compose

How to read the result:

You seeInstalled fromGo to
docker-ce, docker-ce-cli, containerd.ioDocker's own apt repository (or the get.docker.com script)Step 3
docker.io, containerd, runc, docker-compose-v2Ubuntu or Debian repositoriesStep 4
docker in snap listSnap Store (offered in the Ubuntu Server installer)Step 5
/usr/local/bin/docker-composeOld Compose v1 binary downloaded by handStep 6

Step 2. Back up anything you want to keep ​

Deleting Docker data cannot be undone

Step 7 deletes /var/lib/docker and /var/lib/containerd. That removes every image, every container and every named volume, which is where databases and uploaded files usually live. There is no recycle bin. Make a copy first, or take a snapshot of the whole server as described in how to back up your VPS.

Bind mounts (folders like ./data next to a compose.yaml) live outside /var/lib/docker and survive the uninstall. Named volumes do not. List them:

bash
sudo docker volume ls

Stop your containers so files are not changing while you copy them. For a Compose project, run sudo docker compose down in its folder (without -v, which would delete the volumes). Then pack each volume you need into an archive with a throwaway container:

bash
mkdir -p ~/docker-backup
sudo docker run --rm -v VOLUME_NAME:/source:ro -v ~/docker-backup:/backup alpine \
  tar czf /backup/VOLUME_NAME.tar.gz -C /source .

Replace VOLUME_NAME with the name from the list, in both places. Repeat for each volume. For databases, a dump made with the database's own tool (pg_dump, mysqldump) is safer than a copy of its files, so make one while the container is still running.

Also save the files you used to create the containers: compose.yaml, .env files and /etc/docker/daemon.json if you changed it. Copy the archives off the server, for example with scp, before you continue.

Step 3. Remove Docker CE packages ​

This covers Docker installed from download.docker.com, including installs done with the convenience script. purge removes the packages along with their package configuration:

bash
sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
sudo apt autoremove

If apt says some of these packages are not installed, that is fine. Apt skips them.

Step 4. Remove the docker.io package ​

If Docker came from Ubuntu's or Debian's own repositories, the package names are different:

bash
sudo apt purge $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)
sudo apt autoremove

The dpkg --get-selections part expands to the packages from the list that are actually installed, so the command works on both systems even though docker-compose-v2 only exists on Ubuntu.

Step 5. Remove the Docker snap ​

During Ubuntu Server installation it is easy to tick Docker in the list of featured snaps. That version lives completely separately from the apt packages and keeps its data under /var/snap/docker. Remove it, data included:

bash
sudo snap remove --purge docker

--purge skips the automatic snapshot that snapd normally keeps after a removal, so make your backup first.

Step 6. Remove the old docker-compose v1 binary ​

Older guides installed Compose v1 as a single file downloaded with curl. It is not managed by apt, so purging packages leaves it in place. Find it:

bash
which -a docker-compose

Delete each path it prints that is not owned by a package (you can check with dpkg -S /path/to/file). The usual place is:

bash
sudo rm /usr/local/bin/docker-compose

If it was installed with pip, remove it with pip uninstall docker-compose in the same environment it was installed in. A manually installed Compose v2 plugin may also sit in /usr/local/lib/docker/cli-plugins/ or ~/.docker/cli-plugins/. Delete it from there.

Step 7. Delete images, containers and volumes ​

With your backup done, remove Docker's data folders:

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

Then remove configuration that packages do not delete on their own: the daemon settings and each user's client config folder.

bash
sudo rm -rf /etc/docker
rm -rf ~/.docker

Run the last command as every user who used Docker, or remove /home/USER/.docker for each of them. If you set up Docker in rootless mode, that user's data is in ~/.local/share/docker, which you can delete as well.

Step 8. Remove the apt repository and key ​

Current installation guides use these two files:

bash
sudo rm -f /etc/apt/sources.list.d/docker.sources
sudo rm -f /etc/apt/keyrings/docker.asc

Servers set up with older instructions may have a one line docker.list and a key in a different place. Remove those too if they exist:

bash
sudo rm -f /etc/apt/sources.list.d/docker.list
sudo rm -f /etc/apt/keyrings/docker.gpg /usr/share/keyrings/docker-archive-keyring.gpg
sudo apt update

apt update should finish without any line mentioning download.docker.com. If one still appears, search for leftovers with grep -rl download.docker.com /etc/apt/.

Step 9. Remove the docker group ​

The group that allowed running docker without sudo usually survives the uninstall. Delete it:

bash
sudo groupdel docker

If you get group 'docker' does not exist, it is already gone.

Step 10. Check that nothing is left ​

Run these checks. Each one should come back empty or report that nothing was found:

bash
which docker docker-compose dockerd containerd
dpkg -l | grep -Ei 'docker|containerd'
snap list 2>/dev/null | grep -i docker
systemctl list-unit-files | grep -Ei 'docker|containerd'
getent group docker
ls /var/lib/docker /var/lib/containerd

Docker also creates a network interface called docker0, plus a br- interface for every Compose network. They usually stay until the next reboot:

bash
ip link show | grep -E 'docker0|br-|veth'

If they still show up, reboot the server. That also clears the firewall rules Docker created at runtime, because they live only in memory. After the reboot ip link should show only your normal interfaces, such as lo and eth0 or ens3.

Reinstall Docker cleanly ​

A clean reinstall is the main reason people do all of the above. Once the checks pass, follow the guide for your system:

After installing, restore a volume by creating it and unpacking the archive into it:

bash
docker volume create VOLUME_NAME
docker run --rm -v VOLUME_NAME:/target -v ~/docker-backup:/backup alpine \
  tar xzf /backup/VOLUME_NAME.tar.gz -C /target

Do this before starting the Compose project that uses the volume. If the project declares the volume under a project prefix (for example myapp_db-data), use that exact name.

If you only wanted to reset Docker and not remove it, a fresh server can be quicker. On DataPasa you pay by the hour from a prepaid balance, so you can create a new VPS, set it up, move your data and delete the old one without paying for a full month twice. Plans are on the pricing page.

FAQ ​

Does apt remove docker-ce delete my containers? No. Neither remove nor purge touches /var/lib/docker. Images, containers and volumes stay on disk until you delete that folder yourself.

Why does docker still work after I purged the packages? A second copy is installed, usually the snap or a docker.io package. Run which -a docker to see where it lives and remove it with the matching step above.

How much disk space will I get back? Run sudo du -sh /var/lib/docker /var/lib/containerd before deleting them to find out. If you only need space and want to keep Docker, docker system df and docker system prune are the gentler route.

Is it safe to delete /var/lib/containerd if I do not use containerd directly? Yes, when Docker is the only thing on the server using containerd. If you also run Kubernetes or another tool on top of containerd, leave it alone.