How to remove docker

How to remove docker

I tried using docker for something that failed, so I wanted to remove it.

The problem

I thought a simple

sudo apt purge docker.io

would do the job for me. And it seemed like that, until:

Removing docker.io (1.13.1-0ubuntu1~16.04.2) ...
'/usr/share/docker.io/contrib/nuke-graph-directory.sh' -> '/var/lib/docker/nuke-graph-directory.sh'
Purging configuration files for docker.io (1.13.1-0ubuntu1~16.04.2) ...

Nuking /var/lib/docker ...
  (if this is wrong, press Ctrl+C NOW!)

+ sleep 10

/var/lib/docker/nuke-graph-directory.sh: 64: /var/lib/docker/nuke-graph-directory.sh: shopt: not found
dpkg: error processing package docker.io (--purge):
 subprocess installed post-removal script returned error exit status 127
Processing triggers for man-db (2.7.5-1) ...
Errors were encountered while processing:
 docker.io
E: Sub-process /usr/bin/dpkg returned an error code (1)

More specifically, this line:

/var/lib/docker/nuke-graph-directory.sh: 64: /var/lib/docker/nuke-graph-directory.sh: shopt: not found
dpkg: error processing package docker.io (--purge):

For those of you that don’t know:

$ type shopt
shopt is a shell builtin

so, shopt is part of bash, so I edited /var/lib/docker/nuke-graph-directory.sh, and found that the first line was:

#!/bin/sh

and in /bin/sh:

type shopt
shopt: not found

Bam! I found the problem, now how do I fix it?

The solution

It’s quite simple actually, just edit the /var/lib/docker/nuke-graph-directory.sh file, and change the first line to:

#!/bin/bash

and run:

sudo apt purge docker.io

again.

This time, I got:

Nuking /var/lib/docker ...
  (if this is wrong, press Ctrl+C NOW!)

+ sleep 10

+ rm -rf /var/lib/docker/containers /var/lib/docker/image /var/lib/docker/network /var/lib/docker/nuke-graph-directory.sh /var/lib/docker/overlay2 /var/lib/docker/plugins /var/lib/docker/swarm /var/lib/docker/tmp /var/lib/docker/trust /var/lib/docker/volumes
dpkg: warning: while removing docker.io, directory '/etc/docker' not empty so not removed

a simple rm -rf /etc/docker did the job, and everything seems to be removed.

This is what I like about Linux

In Linux distros, you get a real error message if something goes wrong, not just “something went wrong”. If you know what you’re doing, fixing problems in Linux is way easier, thanks to amazing error and debugging logs. If something like this happened on Windows, you’d probably need at least a few days to find solutions, trying everything you see on the internet one by one. With Linux, read the error message, edit a file, and you’re done. Oh, and Linux is free Windows 10 is $100 🙂

Leave a Reply(Markdown is On)

%d bloggers like this: