moby: Deinstall and install of docker ce fails on ubuntu 18.04

Description

After successful docker-ce installation I uninstalled it. The second installation fails.

Steps to reproduce the issue:

I used vagrant to reproduce it:

vagrant init ubuntu/bionic64
vagrant up
vagrant ssh

Then I run the following commands:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get -y update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
sudo apt-get -y purge docker-ce docker-ce-cli containerd.io
sudo apt-get -y install docker-ce docker-ce-cli containerd.io

Describe the results you received:

(I put the above commands in a shell script and run bash -x on that. But I get same failure if I enter commands directly).

+ curl -fsSL https://download.docker.com/linux/ubuntu/gpg
+ sudo apt-key add -
Warning: apt-key output should not be parsed (stdout is not a terminal)
OK
++ lsb_release -cs
+ sudo add-apt-repository 'deb [arch=amd64] https://download.docker.com/linux/ubuntu    bionic    stable'
Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Reading package lists...
+ sudo apt-get -y update
Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:3 https://download.docker.com/linux/ubuntu bionic InRelease
Hit:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists...
+ sudo apt-get -y install docker-ce docker-ce-cli containerd.io
Reading package lists...
Building dependency tree...
Reading state information...
containerd.io is already the newest version (1.4.3-1).
docker-ce-cli is already the newest version (5:20.10.0~3-0~ubuntu-bionic).
docker-ce is already the newest version (5:20.10.0~3-0~ubuntu-bionic).
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up docker-ce (5:20.10.0~3-0~ubuntu-bionic) ...
Setting up docker-ce-rootless-extras (5:20.10.0~3-0~ubuntu-bionic) ...
W: APT had planned for dpkg to do more than it reported back (3 vs 7).
   Affected packages: docker-ce:amd64
+ sudo apt-get -y purge docker-ce docker-ce-cli containerd.io
Reading package lists...
Building dependency tree...
Reading state information...
The following packages were automatically installed and are no longer required:
  libltdl7 pigz
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  containerd.io* docker-ce* docker-ce-cli* docker-ce-rootless-extras*
0 upgraded, 0 newly installed, 4 to remove and 7 not upgraded.
After this operation, 445 MB disk space will be freed.
(Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 60080 files and directories currently installed.)
Removing docker-ce-rootless-extras (5:20.10.0~3-0~ubuntu-bionic) ...
Removing docker-ce (5:20.10.0~3-0~ubuntu-bionic) ...
Warning: Stopping docker.service, but it can still be activated by:
  docker.socket
Removing containerd.io (1.4.3-1) ...
Removing docker-ce-cli (5:20.10.0~3-0~ubuntu-bionic) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
(Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 59851 files and directories currently installed.)
Purging configuration files for docker-ce (5:20.10.0~3-0~ubuntu-bionic) ...
Purging configuration files for containerd.io (1.4.3-1) ...
Processing triggers for systemd (237-3ubuntu10.43) ...
Processing triggers for ureadahead (0.100.0-21) ...
+ sudo apt-get -y install docker-ce docker-ce-cli containerd.io
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  docker-ce-rootless-extras
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
Recommended packages:
  slirp4netns
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras
0 upgraded, 4 newly installed, 0 to remove and 7 not upgraded.
Need to get 0 B/101 MB of archives.
After this operation, 445 MB of additional disk space will be used.
Selecting previously unselected package containerd.io.
(Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 59846 files and directories currently installed.)
Preparing to unpack .../containerd.io_1.4.3-1_amd64.deb ...
Unpacking containerd.io (1.4.3-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../docker-ce-cli_5%3a20.10.0~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.0~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../docker-ce_5%3a20.10.0~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce (5:20.10.0~3-0~ubuntu-bionic) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../docker-ce-rootless-extras_5%3a20.10.0~3-0~ubuntu-bionic_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.0~3-0~ubuntu-bionic) ...
Setting up containerd.io (1.4.3-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-ce-cli (5:20.10.0~3-0~ubuntu-bionic) ...
Setting up docker-ce (5:20.10.0~3-0~ubuntu-bionic) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
invoke-rc.d: initscript docker, action "start" failed.
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Mon 2020-12-14 22:27:40 UTC; 7ms ago
     Docs: https://docs.docker.com
  Process: 7435 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
 Main PID: 7435 (code=exited, status=1/FAILURE)

Dec 14 22:27:40 ubuntu-bionic systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Dec 14 22:27:40 ubuntu-bionic systemd[1]: docker.service: Failed with result 'exit-code'.
Dec 14 22:27:40 ubuntu-bionic systemd[1]: Failed to start Docker Application Container Engine.
dpkg: error processing package docker-ce (--configure):
 installed docker-ce package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of docker-ce-rootless-extras:
 docker-ce-rootless-extras depends on docker-ce; however:
  Package docker-ce is not configured yet.

dpkg: error processing package docker-ce-rootless-extras (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for systemd (237-3ubuntu10.43) ...
Errors were encountered while processing:
 docker-ce
 docker-ce-rootless-extras
E: Sub-process /usr/bin/dpkg returned an error code (1)

Describe the results you expected:

I would expect that I could install docker a second time. I had also no success if I add docker-ce-rootless-extras to docker purge.

Additional information you deem important (e.g. issue happens only occasionally):

Looks similar https://github.com/docker/for-linux/issues/1154 (report of version included in repository).

Similar to https://github.com/moby/moby/issues/41781 but there docker installation succeed and the rootless scripts fails.

Output of docker version:

(after running above installation steps)

Client: Docker Engine - Community
 Version:           20.10.0
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        7287ab3
 Built:             Tue Dec  8 18:59:53 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Output of docker info:

(after running above installation steps)

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.4.2-docker)

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info

Additional environment details (AWS, VirtualBox, physical, etc.):

vagrant virtual box with ubuntu 18.04.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 10
  • Comments: 49 (7 by maintainers)

Commits related to this issue

Most upvoted comments

@nik098: I had the same issue. In my case, VPN was the culprit. Turning off the VPN helped with the successful installation.

After playing around I solved my issue & now it re-installs 100% fine each time, so far. However the docker dev team should still fix this as running an extra command isn’t a permanent solution. Just doing a normal purge & install eachtime should work.

Solution is: before purging I run this:

sudo systemctl stop docker.socket

Then next install it works fine. Repeat above step each time before purging & it re-installs fine each time. Tried 5 times in a row. Without stopping the socket first & directly purging then it re-installs every alternative time only.

I’ve solved.

Before a re-installation, I executed a below command.

$ sudo rm -rf /var/lib/docker

And re-install.

$ sudo apt install -y docker-ce docker-ce-cli containerd.io

A service status is OK.

$ sudo service docker status
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-01-25 10:58:08 JST; 31s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 5188 (dockerd)
      Tasks: 13
     CGroup: /system.slice/docker.service
             └─5188 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Hope someone still needs help. I have done the following process to fix Ubuntu 20.04.2 LTS. Please add sudo if you are not root.

  1. systemctl stop docker
  2. mv /var/lib/dpkg/info/docker-ce* /tmp
  3. apt-get purge docker-ce docker-ce-cli containerd.io -y
  4. apt-get remove docker docker-engine docker.io containerd runc
  5. apt-get update
  6. apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  7. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  8. sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”
  9. apt-get update
  10. apt-get install docker-ce docker-ce-cli containerd.io

Using Ubuntu 20.04 bionic,

I had a exact same issue, turns out docker was not installed properly.

First completely remove docker using the following:

dpkg -l | grep -i docker

remove all the packages listed by running:

sudo apt-get purge -y <package_name>

also run the following commands:

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

Now reinstall the docker in the following order:

sudo apt install apt-transport-https curl lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update

sudo apt install containerd.io

sudo apt install docker-ce-cli

sudo apt install docker-ce 

sudo docker run hello-world

Install the containered.io package first.

None of the commands above have been able to solve the issue for me on Ubuntu 20.04.2 LTS

Here the output:

$ sudo journalctl -f -u docker 
-- Logs begin at Tue 2020-12-15 09:24:21 UTC. --
Dec 15 09:26:06 ubuntu-bionic dockerd[5348]: failed to load listeners: no sockets found via socket activation: make sure the service was started by systemd
Dec 15 09:26:06 ubuntu-bionic systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Dec 15 09:26:06 ubuntu-bionic systemd[1]: docker.service: Failed with result 'exit-code'.
Dec 15 09:26:06 ubuntu-bionic systemd[1]: Failed to start Docker Application Container Engine.
Dec 15 09:26:08 ubuntu-bionic systemd[1]: docker.service: Service hold-off time over, scheduling restart.
Dec 15 09:26:08 ubuntu-bionic systemd[1]: docker.service: Scheduled restart job, restart counter is at 4.
Dec 15 09:26:08 ubuntu-bionic systemd[1]: Stopped Docker Application Container Engine.
Dec 15 09:26:08 ubuntu-bionic systemd[1]: docker.service: Start request repeated too quickly.
Dec 15 09:26:08 ubuntu-bionic systemd[1]: docker.service: Failed with result 'exit-code'.
Dec 15 09:26:08 ubuntu-bionic systemd[1]: Failed to start Docker Application Container Engine.

If I run after the failure

sudo apt-get -y purge docker-ce docker-ce-cli containerd.io

and restart system then following works (but a system restart looks only like a workaround):

sudo apt-get -y install docker-ce docker-ce-cli containerd.io

If I run after this

sudo apt-get -y purge docker-ce docker-ce-cli containerd.io
sudo apt-get -y install docker-ce docker-ce-cli containerd.io

it fails again with the same error.

As I said, it installs fine every alternative install so workaround is just purge & install again & it will work. But next purge/install it won’t, then next purge/install it will. This issue is only with Docker. I tried other apps like Elasticsearch & Nginx, and those don’t give error on followup installs so it can’t be my env. And I haven’t customized my OS; it is the basic LTS install the VPS provider images. Not a big issue since there is a work around.

Issue is replicable 100% of the time. To replicate repeat this (Ive also tried by having few minutes time gap too in between commands but same issue):

yes | sudo apt install docker-ce docker-ce-cli containerd.io
yes | sudo apt purge docker-ce docker-ce-cli containerd.io
yes | sudo apt install docker-ce docker-ce-cli containerd.io
yes | sudo apt purge docker-ce docker-ce-cli containerd.io
yes | sudo apt install docker-ce docker-ce-cli containerd.io
yes | sudo apt purge docker-ce docker-ce-cli containerd.io
...

In journal this appears:

Dec 23 09:02:21 test0 systemd[1]: docker.service: Scheduled restart job, restart counter is at 5.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Automatic restarting of the unit docker.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Dec 23 09:02:21 test0 systemd[1]: Stopped Docker Application Container Engine.
-- Subject: A stop job for unit docker.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit docker.service has finished.
--
-- The job identifier is 1775 and the job result is done.
Dec 23 09:02:21 test0 systemd[1]: docker.service: Start request repeated too quickly.
Dec 23 09:02:21 test0 systemd[1]: docker.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit docker.service has entered the 'failed' state with result 'exit-code'.
Dec 23 09:02:21 test0 systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: A start job for unit docker.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit docker.service has finished with a failure.
--
-- The job identifier is 1775 and the job result is failed.
Dec 23 09:02:21 test0 systemd[1]: docker.socket: Failed with result 'service-start-limit-hit'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit docker.socket has entered the 'failed' state with result 'service-start-limit-hit'.

I had this exact same problem and what seems to have fixed it for me was running this:

sudo rm -rf /etc/systemd/system/docker.service.d

I also suggest running:


sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
sudo rm -Rf /etc/docker 

Purge everything docker afterwards and reinstall.

I also have this problem on Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-60-generic x86_64)

Can neither upgrade nor remove/purge docker-ce. It hangs either way.

I reisntalled my server from scratch.

Found a thread on stack overflow for that error that mentions loading ip_tables worked; https://stackoverflow.com/a/22876662

sudo modprobe ip_tables
sudo echo 'ip_tables' >> /etc/modules

Also on that thread;

It seems that the error can occur if the kernel image was updated and the system was not restarted thereafter.

So might be worth trying if installation completes successfully after a restart of the machine 🤔

sudo rm -rf /etc/docker/daemon.json

After playing around I solved my issue & now it re-installs 100% fine each time, so far. However the docker dev team should still fix this as running an extra command isn’t a permanent solution. Just doing a normal purge & install eachtime should work.

Solution is: before purging I run this:

sudo systemctl stop docker.socket

Then next install it works fine. Repeat above step each time before purging & it re-installs fine each time. Tried 5 times in a row. Without stopping the socket first & directly purging then it re-installs every alternative time only.

Thank you SO much, I am running into Ansible automation issues due to this and was having a hell of a time tracking it down!

For me it was: sudo systemctl unmask docker
sudo systemctl enable docker
sudo apt remove --purge docker docker.io containerd runc
sudo rm -Rf /etc/docker

I had the same problem and none of the advice given above helped. Ubuntu 20.04 LTS, latest versions of docker-ce. Installs and purging would both hang without even the ability to CTRL+C. I had to kill the process while it’s hanging to get it to stop and then do a dance of purge/kill in two terminals to get a purge to complete. Stopping the socket service would sometimes work as well but that itself would hang.

The only way for me to get it installed was to revert to the previous version of docker-ce and docker-ce-cli. In the process, i also lost all my containers (perhaps because i moved the /var/lib/docker dir away and back again later after one of the ideas floated here or there)

sudo apt-get install docker-ce=5:20.10.0~3-0~ubuntu-bionic docker-ce-cli=5:20.10.0~3-0~ubuntu-bionic containerd.io