# 更新现有软件包列表$ sudo apt update# 安装一些必备软件包,让 apt 通过 HTTPS 使用软件包$ sudo apt install apt-transport-https ca-certificates curl software-properties-common# 将官方 Docker 版本库的 GPG 密钥添加到系统中$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -# 将 Docker 版本库添加到 APT 源$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"# 用新添加的 Docker 软件包来进行升级更新$ sudo apt update# 确保要从 Docker 版本库,而不是默认的 Ubuntu 版本库进行安装$ apt-cache policy docker-ce# 安装 Docker$ sudo apt install docker-ce
一些错误:出错原因上一块代码中,第 8 行末尾多加了一个 $,已修改。
root@u253:~# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"Hit:1 http://mirrors.aliyun.com/ubuntu focal InReleaseHit:2 http://mirrors.aliyun.com/ubuntu focal-updates InReleaseHit:3 http://mirrors.aliyun.com/ubuntu focal-backports InReleaseHit:4 http://mirrors.aliyun.com/ubuntu focal-security InReleaseGet:5 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]Err:5 https://download.docker.com/linux/ubuntu focal InReleaseThe following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8Reading package lists... DoneW: 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 7EA0A9C3F273FCD8E: 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.
注意第十行的 NO_PUBKEY,我们要使用错误提示中给的公钥
$ sudo gpg --keyserver keyserver.ubuntu.com --recv 7EA0A9C3F273FCD8$ sudo gpg --export --armor 7EA0A9C3F273FCD8 | sudo apt-key add -$ sudo apt-get update
