Installing Docker Engine - lmmx/devnotes GitHub Wiki

The following guide is for me, on Linux Mint (Ubuntu base distro).

First remove old versions

sudo apt-get remove docker docker-engine docker.io containerd runc

This did nothing...

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'docker-engine' is not installed, so not removed
Package 'docker' is not installed, so not removed
Package 'containerd' is not installed, so not removed
Package 'runc' is not installed, so not removed
Package 'docker.io' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  libmdb2 libmdbsql2 libudev1:i386 libxmlsec1-openssl shotwell-common zerofree
Use 'sudo apt autoremove' to remove them.
0 to upgrade, 0 to newly install, 0 to remove and 496 not to upgrade.

The docs say to ignore this

It’s OK if apt-get reports that none of these packages are installed.

...however this doesn't actually clarify whether this means the necessary uninstallation has taken place or not (the fact that I still have a working docker command strongly suggests it didn't).

For better or worse I'm going to attempt to continue by assuming that all that was required was to uninstall the packages...

My version of docker is installed as a binary in /usr/bin, and unfortunately I don't remember exactly how I put it there...

I had more success following the advice on askubuntu here:

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

That was all I needed to get rid of docker on the command line. You can go further to remove containers and images, but I didn't want that:

The above commands will not remove images, containers, volumes, or user created configuration files on your host. If you wish to delete all images, containers, and volumes 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

So back to Docker Compose: I chose the recommended option of installing via repository.

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

I then ran the line in the guide (warning: here I made a mistake, do not repeat if using Linux Mint)

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg]
https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

and here I noticed an error:

Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]                
Ign:6 https://download.docker.com/linux/ubuntu ulyssa InRelease                          
Ign:7 http://packages.linuxmint.com ulyssa InRelease
Err:8 https://download.docker.com/linux/ubuntu ulyssa Release
  404  Not Found [IP: 216.137.44.7 443]
Hit:9 http://packages.linuxmint.com ulyssa Release

What had happened was that I was trying to use the Linux Mint distro release name (ulyssa) rather than the base Ubuntu distro release name (focal).

In the last shell command, the output of $(lsb_release -cs) was included in an STDOUT echo tee'd to /etc/apt/sources.list.d/docker.list, and since the OS is Mint not Ubuntu that resulted in -c (codename) -s (short) --> ulyssa. What should have come out was focal.

Under the hood, I expect the lsb_release tool is reading /etc/lsb-release.

Linux Mint also has /etc/upstream-release/lsb-release which can be read to give "fossa" as:

cat /etc/upstream-release/lsb-release | grep -m 1 CODENAME | cut -d = -f 2 | tr -d "\n"

So that last command should have been:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu \
  $(cat /etc/upstream-release/lsb-release \
  | grep -m 1 DISTRIB_CODENAME | cut -d\= -f 2 | tr -d "\n") stable" \
  | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Now when I updated my packages there was no 404 error:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

When I ran the update, there were no messages about the docker repos, but when I ran apt-get install I could see packages coming from there.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite
The following NEW packages will be installed
  docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin
  docker-scan-plugin pigz slirp4netns
The following packages will be upgraded:
  containerd.io
1 to upgrade, 7 to newly install, 0 to remove and 705 not to upgrade.
Need to get 108 MB of archives.
After this operation, 339 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB]
Get:3 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.6.6-1 [28.1 MB]
Get:4 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-cli amd64 5:20.10.17~3-0~ubuntu-focal [40.6 MB]
Get:5 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce amd64 5:20.10.17~3-0~ubuntu-focal [21.0 MB]
Get:6 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-ce-rootless-extras amd64 5:20.10.17~3-0~ubuntu-focal [8,171 kB]
Get:7 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-compose-plugin amd64 2.6.0~ubuntu-focal [6,560 kB]
Get:8 https://download.docker.com/linux/ubuntu focal/stable amd64 docker-scan-plugin amd64 0.17.0~ubuntu-focal [3,521 kB]
Fetched 108 MB in 11s (10.2 MB/s)                                                        
Selecting previously unselected package pigz.
(Reading database ... 534775 files and directories currently installed.)
Preparing to unpack .../0-pigz_2.4-1_amd64.deb ...
Unpacking pigz (2.4-1) ...
Preparing to unpack .../1-containerd.io_1.6.6-1_amd64.deb ...
Unpacking containerd.io (1.6.6-1) over (1.4.12-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../2-docker-ce-cli_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../3-docker-ce_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../4-docker-ce-rootless-extras_5%3a20.10.17~3-0~ubuntu-focal_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-focal) ...
Selecting previously unselected package docker-compose-plugin.
Preparing to unpack .../5-docker-compose-plugin_2.6.0~ubuntu-focal_amd64.deb ...
Unpacking docker-compose-plugin (2.6.0~ubuntu-focal) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../6-docker-scan-plugin_0.17.0~ubuntu-focal_amd64.deb ...
Unpacking docker-scan-plugin (0.17.0~ubuntu-focal) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../7-slirp4netns_0.4.3-1_amd64.deb ...
Unpacking slirp4netns (0.4.3-1) ...
Setting up slirp4netns (0.4.3-1) ...
Setting up docker-scan-plugin (0.17.0~ubuntu-focal) ...
Setting up containerd.io (1.6.6-1) ...
Installing new version of config file /etc/containerd/config.toml ...
Setting up docker-compose-plugin (2.6.0~ubuntu-focal) ...
Setting up docker-ce-cli (5:20.10.17~3-0~ubuntu-focal) ...
Setting up pigz (2.4-1) ...
Setting up docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-focal) ...
Setting up docker-ce (5:20.10.17~3-0~ubuntu-focal) ...
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 Sun 2022-06-26 22:46:03 BST; 3ms ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
    Process: 3703687 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
   Main PID: 3703687 (code=exited, status=1/FAILURE)
dpkg: error processing package docker-ce (--configure):
 installed docker-ce package post-installation script subprocess returned error exit status 1
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for systemd (245.4-4ubuntu3.6) ...
Errors were encountered while processing:
 docker-ce
E: Sub-process /usr/bin/dpkg returned an error code (1)

In short, there was an error with docker-ce.

Unfortunately I got an installation error.

I suspected this may have been due to not having restarted, and restarted my machine.

(If you think about it, that post-installation check relies on docker, which has just been reinstalled, and is notorious for not working until restarting.)

...and I was right! Re-running the same command as above led to

Reading package lists... Done
Building dependency tree       
Reading state information... Done
containerd.io is already the newest version (1.6.6-1).
docker-ce-cli is already the newest version (5:20.10.17~3-0~ubuntu-focal).
docker-ce is already the newest version (5:20.10.17~3-0~ubuntu-focal).
docker-compose-plugin is already the newest version (2.6.0~ubuntu-focal).
0 to upgrade, 0 to newly install, 0 to remove and 705 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up docker-ce (5:20.10.17~3-0~ubuntu-focal) ...

A quick check of docker images showed my old container images were still there and visible to Docker.

The official docs say to run sudo docker run hello-world and this likewise confirmed containers could run.