How To Completely Remove Docker From Your Debian Based Linux

This is a simple note to myself of how to remove Docker from Ubuntu or Raspberry Pi OS (previously called Raspbian). Credit goes to Mayur Bhandare on Stack Exchange. I also added some explanation to some of the commands so you will have a better understanding of what they’re doing.

1. Identify which Docker package have you installed
dpkg -l | grep -i docker
For example, I’ve installed docker-ce and docker-ce-cli

The dpkg command is a package management command in Debian. Just like apt-get in Ubuntu, a Linux distro based on Debian. Since Raspberry Pi OS is also a descendant of Debian, this will work just fine. The above command is basically saying, give me a list of packages that contains the word “docker” in them.

2. Remove the packages

For me, I’ve only installed docker-ce and docker-ce-cli. So I will run the following commands.

sudo apt-get purge -y docker-ce docker-ce-cli
sudo apt-get autoremove -y --purge docker-ce docker-ce-cli

If you have more docker packages installed, you can add those packages names to the end of the commands above. For example:

sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli
sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce 

The “-y” flag here is to answer “yes” to the command prompt when it asks you whether to remove a package. You can choose to remove the “-y” flag. Then you’ll see prompts like the following and you have to manually answer yes or y for every package.

3. Remove all the Docker related files

After that, you might want to remove all the Docker images, containers, volumes, and configurations. This is how:

sudo rm -rf /var/lib/docker /etc/docker
sudo rm /etc/apparmor.d/docker
sudo groupdel docker
sudo rm -rf /var/run/docker.sock

The “-rf ” flag is a combination of the “-r” and “-f” flags. “-r” means recursive. So the rm command can remove all the children folders and files of the target folder recursively. “-f” means force. It will ignore non-existent files, and never prompt before removing them. Be careful when you use these two flags together.

The groupdel command is to delete an existing docker user group.

Bonus: Deactivate Network Interface and Ethernet Bridge

If you want to take one step further, you can deactivate the docker0 network interface and delete the docker0 ethernet bridge. Here’s how(Credit: Thanks to anony for mentioning that!😁):

To disable docker0 network interface:

sudo ifconfig docker0 down

To delete the existing docker0 ethernet bridge:

sudo ip link delete docker0

The brctl command is deprecated. Updated the above command. Credit to Nicolas Raoul and Søren (Edited on 2024-03-26)

Congratulations! You have just completely removed Docker from your system!

If my note helped, please consider buying me a coffee😁.

Cheers,
Lok

Comments

16 responses to “How To Completely Remove Docker From Your Debian Based Linux”

  1. dietrich Avatar
    dietrich

    Great, thanks! Had a lot of trouble with it, kernel not matching with cgroup etc. and all the tipps online i could get were nonsens.
    with your help my system is clean after my first errors with docker. Not mentioned: clean the sources.list!

    1. Lok C Avatar
      Lok C

      I’m glad that it helps 😄

  2. cotchon Avatar
    cotchon

    Thank you for the straight forward Docker removing method !!

    1. Lok C Avatar
      Lok C

      No problem! Glad that it helps!

  3. Tim C. Avatar
    Tim C.

    When I entered /var/run to remove docker.sock I noticed there’s a docker directory as well ‘/var/run/docker’. Forgive this noob, but should that be removed too?

    1. Lok C Avatar
      Lok C

      Yes, you can remove it with the following command:
      sudo rm -rf /var/run/docker.sock

      This command is the 4th line in the 3rd step. I hope it helps😊

      1. Chris Avatar
        Chris

        What about the directory `/var/run/docker`? Should that be removed, too?

        1. Lok C Avatar
          Lok C

          Yes. You can do that in step 3.

  4. anony Avatar
    anony

    You may want to run these two commands as well at the end:

    # ifconfig docker0 down

    # brctl delbr docker0

    1. Lok C Avatar
      Lok C

      Thanks for the info! I’ve added a bonus step to the blog post😁.

  5. Bernie Dahlstrom Avatar

    This was the clearest and cleanest page of instructions I have ever used.
    Many thanks to Lok C and all the individules given credit herein.

    Great job — Bernie

    1. Lok C Avatar
      Lok C

      I’m glad that it helps😁

  6. Nicolas Raoul Avatar

    About the section “Deactivate Network Interface and Ethernet Bridge”:

    1. You must prefix each command with sudo
    2. The commands use `docker0` but the explanation read like “dockero”, which can be confusing. Maybe change the font or put `docker0` in inline source form.
    3. brctl has been deprecated and does not exist anymore on most distributions. I successfully used this command instead: ip link delete docker0

    Thanks!

    1. Lok C Avatar
      Lok C

      Thanks for the suggestion! I’ve updated the post accordingly.

  7. Søren Avatar

    I didn’t have `brctl` but `sudo ip link delete docker0` did the trick for me. Thank you for posting this!

    1. Lok C Avatar
      Lok C

      Thanks for the suggestion! I’ve updated the post.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.