19

I have installed the docker with

curl -sSL https://get.docker.com/ | sh

When I tried to uninstall the package, I am facing the following error

$ sudo apt-get remove docker-engine
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  docker-engine
0 upgraded, 0 newly installed, 1 to remove and 5 not upgraded.
1 not fully installed or removed.
After this operation, 28.5 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 454135 files and directories currently installed.)
Removing docker-engine (1.8.2-0~vivid) ...
Failed to stop docker.service: Unit docker.service not loaded.
invoke-rc.d: initscript docker, action "stop" failed.
dpkg: error processing package docker-engine (--remove):
 subprocess installed pre-removal script returned error exit status 5
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 docker-engine
E: Sub-process /usr/bin/dpkg returned an error code (1)

How am I to uninstall the docker package?

I am using Ubuntu 15.04.

1

5 Answers 5

32

Try it

sudo mv /var/lib/dpkg/info/{packagename}.* /tmp/
sudo dpkg --remove --force-remove-reinstreq {packagename}
sudo apt-get remove {packagename}
sudo apt-get autoremove && sudo apt-get autoclean
1
  • This leaves files behind.
    – Mala
    Feb 2, 2020 at 4:26
7

I had the same problem but in Ubuntu 14.04. The way that I resolve this problem was:

First remove bad links:

sudo mv /var/lib/dpkg/info/{packagename}.* /tmp/
sudo apt-get remove {packagename}

So now you can install it again:

sudo apt-get install docker-engine

Thats all.

3

The problem is that Docker tries to stop itself upon uninstall, and you've never actually run it successfully so it's not running. Have a look at /var/lib/dpkg/info/docker-ce.prerm. It will look something like this:

#!/bin/sh
set -e
# Automatically added by dh_installinit/12.1.1
if [ -x "/etc/init.d/docker" ]; then
        invoke-rc.d docker stop || exit 1
fi
# End automatically added section

You can easily spot the logic flaw here: it assumes that if the init script exists, the docker daemon must be running. However, if you've installed it on a platform where it doesn't actually work (e.g. WSL, etc.) that won't be the case.

Since stopping docker is the only thing the prerm script does, and docker for sure isn't running on your system, just delete the file, after which you'll be able to apt remove docker-ce like normal.

2

Doesn't look like a Docker specific issue, rather like general installation problem.

Did docker ever work on that machine (as in: did the installation even succeed?)

I would start looking into Failed to stop docker.service: Unit docker.service not loaded and see if that leads to any more insights on what's going wrong. Seems like it's unable to stop the service.

You might need to read up a bit about systemd, I recommend this page. journalctl might be helpful as well, see here.

And then:

  • Does docker.service exist?
  • Can it be loaded?
  • What's its status?
  • What does it say if you start it?
  • Stop it?

ps: Not a big fan of fully automated installation scripts. I don't see what's wrong with apt-get install docker-engine...

1
  • 1
    Thanks. There was another instance of docker.io on the same machine installed through aptitude. While installing docker.engine, it warned me but I still went ahead and installed the docker.engine. Then uninstalled docker.io and then tried to uninstall docker.engine. That is when I got this error. I know this is not very clean way to install. Then reason I install from the automated installation script is because docker doc said so. I solved by using ugliest possible method. i.e. rm /lib/systemd/system/docker.*; rm /usr/bin/docker; aptitude purge docker.engine. Now clean install seems fine.
    – UnSat
    Oct 7, 2015 at 19:48
2

If you want to remove everything that comes with the Docker Toolbox (including Docker Engine).

You can execute this shell script:

#!/bin/bash

# Uninstall Script

if [ "${USER}" != "root" ]; then
    echo "$0 must be run as root!"
    exit 2
fi

while true; do
  read -p "Remove all Docker Machine VMs? (Y/N): " yn
  case $yn in
    [Yy]* ) docker-machine rm -f $(docker-machine ls -q); break;;
    [Nn]* ) break;;
    * ) echo "Please answer yes or no."; exit 1;;
  esac
done

echo "Removing Applications..."
rm -rf /Applications/Docker

echo "Removing docker binaries..."
rm -f /usr/local/bin/docker
rm -f /usr/local/bin/docker-machine
rm -r /usr/local/bin/docker-machine-driver*
rm -f /usr/local/bin/docker-compose

echo "Removing boot2docker.iso"
rm -rf /usr/local/share/boot2docker

echo "All Done!"

If you still have the depreciated Boot2docker and you want to get rid of it as well.

You can uninstall it by executing the following shell script:

#!/bin/bash

# Uninstall Script

if [ "$(which boot2docker)" == "" ]; then
    echo "boot2docker does not exist on your machine!"
    exit 1
fi

if [ "${USER}" != "root" ]; then
    echo "$0 must be run as root!"
    exit 2
fi

echo "Stopping boot2docker processes..."
boot2docker stop && boot2docker delete

echo "Removing boot2docker executable..."
rm -f /usr/local/bin/boot2docker

echo "Removing boot2docker ISO and socket files..."
rm -rf ~/.boot2docker
rm -rf /usr/local/share/boot2docker

echo "Removing boot2docker SSH keys..."
rm -f ~/.ssh/id_boot2docker*

echo "Removing boot2docker OSX files..."
rm -f /private/var/db/receipts/io.boot2docker.*
rm -f /private/var/db/receipts/io.boot2dockeriso.*

echo "Removing Docker executable..."
rm -f /usr/local/bin/docker

echo "All Done!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.