Skip to content
Follow
Ubuntu Linux

How to Completely Uninstall Docker from Ubuntu

Richard
Written by
Richard
Oct 7, 2023 Updated Oct 13, 2026 4 min read
How to Change Default Apps in Ubuntu
How to Change Default Apps in Ubuntu

Uninstalling Docker from Ubuntu means removing the main program and also the containers, images, volumes and configuration files that a normal package removal leaves behind. Docker is a tool that runs applications inside isolated boxes called containers, so they stay separate from the rest of your system.

Advertisement

Leftover Docker files can take up many gigabytes of disk space. They can also cause odd errors when you install Docker again later. This guide removes every trace of Docker in the right order, so you get the space back and a clean slate for a fresh install.

⚡ Quick Answer

Completely uninstall Docker by first removing all containers, images, networks, and volumes using docker commands. Then, remove the Docker packages with sudo apt remove docker-* –auto-remove and clean up residual directories like /var/lib/docker.

Advertisement

Delete Docker images, containers, and volumes

The order matters. First remove the Docker objects: containers, images, networks and volumes. Then remove the Docker packages and the files they leave behind. If you remove the packages first, the Docker commands you need for cleanup are gone, and the data stays on your disk.

Run the stop command to halt anything that is running. Then use the system prune command to clear out the stored data, container files and local volumes. Remove the software package last.

⚠️Warningthis process permanently deletes your containers and everything stored in Docker volumes, including databases.

If you want to keep any of that data, copy it somewhere else before you start. You also need a user with sudo rights.

The cleanup has several parts. Work through them in order and run each command in a terminal window.

Advertisement

Halt all active containers first. A running container can block the removal of its image or volume, so stop them before anything else. Run this command:

Next, remove the containers themselves. A stopped container still sits on your disk until you delete it. Run the command below to do that.

If you have no containers, the command may print a usage message or an error about missing arguments. That is harmless, so move on to the next step.

💻Code
docker stop $(docker ps -a -q)

You can also stop all active containers and remove them in one go. Use this command:

Advertisement

When it finishes, the command prints the IDs of the containers it removed. You should see no containers left.

💻Code
docker rm $(docker ps -a -q)

Next, remove Docker images. Images are usually the biggest users of disk space. Run the command below to do that. It lists all active and intermediate images and removes them from your system.

You will see a list of deleted or untagged image IDs scroll past. If an image is still in use by a container, Docker refuses to delete it. Go back and remove that container first.

💻Code
docker rmi $(docker images -a -q)

Next, remove all Docker networks. This command removes the custom networks Docker created on your system. The default networks that Docker ships with cannot be deleted, so you may see a message about them. That is normal.

Advertisement
💻Code
docker network prune

Next, clear out the remaining cache and volumes with this prune command. It also catches anything the earlier commands missed:

💻Code
docker system prune -a

This single command sweeps away the following items, which are listed below. Docker prints a warning that shows what it is about to delete before it does anything.

  • 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

Docker asks you to confirm before it deletes anything. Type y and press Enter when the confirmation prompt appears. If you press Enter alone, or type n, Docker cancels and nothing is removed. When the command ends, it reports how much disk space it reclaimed.

Now remove the Docker packages and delete the leftover files. Run the following commands in order. Each one needs sudo, and you may be asked for your password. This step ensures no Docker data remains on your Ubuntu system after the removal.

Advertisement

You do not need to restart the machine. To check the result, open a new terminal and try the docker command. Ubuntu should say it cannot find it. If you ever want Docker back, you can install it again as if the machine had never had it.

🐧Bash / Shell
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! Docker and its data are gone from your system, and the disk space is free again.

Conclusion:

  • This guide covered how to uninstall Docker from Ubuntu Linux. You stopped and removed containers, deleted images, networks and volumes, removed the packages, and cleared out leftover files and configuration.
  • Following these steps in order frees up disk space and removes Docker and its related components completely, so a later reinstall starts clean.
  • If you ran into a problem or have a tip of your own, share it in the comments for other readers.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

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