1. # 更新现有软件包列表
    2. $ sudo apt update
    3. # 安装一些必备软件包,让 apt 通过 HTTPS 使用软件包
    4. $ sudo apt install apt-transport-https ca-certificates curl software-properties-common
    5. # 将官方 Docker 版本库的 GPG 密钥添加到系统中
    6. $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    7. # 将 Docker 版本库添加到 APT 源
    8. $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
    9. # 用新添加的 Docker 软件包来进行升级更新
    10. $ sudo apt update
    11. # 确保要从 Docker 版本库,而不是默认的 Ubuntu 版本库进行安装
    12. $ apt-cache policy docker-ce
    13. # 安装 Docker
    14. $ sudo apt install docker-ce

    一些错误:出错原因上一块代码中,第 8 行末尾多加了一个 $,已修改。

    1. root@u253:~# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
    2. Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
    3. Hit:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease
    4. Hit:3 http://mirrors.aliyun.com/ubuntu focal-backports InRelease
    5. Hit:4 http://mirrors.aliyun.com/ubuntu focal-security InRelease
    6. Get:5 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]
    7. Err:5 https://download.docker.com/linux/ubuntu focal InRelease
    8. The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
    9. Reading package lists... Done
    10. 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
    11. E: The repository 'https://download.docker.com/linux/ubuntu focal InRelease' is not signed.
    12. N: Updating from such a repository can't be done securely, and is therefore disabled by default.
    13. N: See apt-secure(8) manpage for repository creation and user configuration details.

    注意第十行的 NO_PUBKEY,我们要使用错误提示中给的公钥

    1. $ sudo gpg --keyserver keyserver.ubuntu.com --recv 7EA0A9C3F273FCD8
    2. $ sudo gpg --export --armor 7EA0A9C3F273FCD8 | sudo apt-key add -
    3. $ sudo apt-get update