参考官方安装地址:https://docs.docker.com/engine/install/ubuntu/

要安装 Docker Engine,您需要以下 Ubuntu 版本之一的 64 位版本:

  • Ubuntu 小鬼 21.10
  • Ubuntu 多毛 21.04
  • Ubuntu 焦点 20.04 (LTS)
  • Ubuntu 仿生 18.04 (LTS)
卸载老版本
$ sudo apt-get remove docker docker-engine docker.io containerd runc

设置新的储存器

更新apt包索引并安装包以允许apt通过 HTTPS 使用存储库

$ sudo apt-get update

$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

添加官方的GPG密钥

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

使用以下命令设置稳定存储库

$ echo \
  "deb [arch=$(dpkg --print-architecture) 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

安装 Docker 引擎

$ sudo apt-get update

问题:
E: The repository 'https://download.docker.com/linux/ubuntu \ Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details

忽略

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

报错:
Reading package lists... Done
Building dependency tree    
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'docker-ce' has no installation candidate
E: Unable to locate package docker-ce-cli
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
E: Couldn't find any package by regex 'containerd.io'

编辑ubuntu源 /etc/apt/sources.list

$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.back

$ sudo vi /etc/apt/sources.list

最后增加
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
$ sudo apt-get update

Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:3 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]
Err:3 https://download.docker.com/linux/ubuntu bionic InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
Hit:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Get:5 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]
Err:5 https://download.docker.com/linux/ubuntu focal InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
Hit:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
W: GPG error: https://download.docker.com/linux/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
E: The repository 'https://download.docker.com/linux/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: https://download.docker.com/linux/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
E: The repository 'https://download.docker.com/linux/ubuntu focal InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

将公钥添加至服务器,即终端中输入

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys '7EA0A9C3F273FCD8'

Executing: /tmp/apt-key-gpghome.VIv8eLEwb3/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8
gpg: key 8D81803C0EBFCD88: 9 signatures not checked due to missing keys
gpg: key 8D81803C0EBFCD88: public key "Docker Release (CE deb) <docker@docker.com>" imported
gpg: Total number processed: 1
gpg:              imported: 1
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

参考:https://www.jianshu.com/p/5b7c1d02f958

添加软件源

$ sudo mkdir -p /etc/docker
$ sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://mirror.aliyuncs.com"]
}
EOF
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

这里的registry-mirrors可以替换成任意源