在 ubuntu20 上安装 docker

步骤如下

更新 apt-get 源

sudo apt-get update

安装包允许 apt-get 通过 https 使用仓库

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

添加 docker 官方 GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

设置 docker 稳定版仓库

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

设置完毕仓库,重新更新源

sudo apt-get update

更新上面的源时,可能会出现如下错误

获取:1 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]                                                                                                   
忽略:2 https://download.docker.com/linux/ubuntu focal InRelease                                                                                                                          
错误:3 https://download.docker.com/linux/ubuntu focal Release                                                                                              
  404  Not Found [IP: 13.225.103.65 443]
命中:4 http://mirrors.163.com/ubuntu focal InRelease                                                                                  
命中:5 http://mirrors.163.com/ubuntu focal-updates InRelease                                                                          
命中:6 http://mirrors.163.com/ubuntu focal-backports InRelease                                                 
忽略:7 http://dl.google.com/linux/chrome/deb stable InRelease                                     
命中:8 http://dl.google.com/linux/chrome/deb stable Release                  
命中:9 http://archive.ubuntukylin.com:10006/ubuntukylin trusty InRelease
正在读取软件包列表... 完成                                                                                                                                                                                  
E: 仓库 “https://download.docker.com/linux/ubuntu focal Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。

处理方法

在 /etc/apt/source.list 文件中增加如下配置

deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable

再次更新源

sudo apt-get update

可能会出现如下错误

获取:1 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]                                                                                                   
获取:2 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]                                                                                                               
命中:3 http://mirrors.163.com/ubuntu focal InRelease                                                                                                                                     
命中:4 http://mirrors.163.com/ubuntu focal-updates InRelease                                                                          
命中:5 http://mirrors.163.com/ubuntu focal-backports InRelease                                                                      
忽略:6 http://dl.google.com/linux/chrome/deb stable InRelease                                                                       
命中:7 http://dl.google.com/linux/chrome/deb stable Release                                       
命中:8 http://archive.ubuntukylin.com:10006/ubuntukylin trusty InRelease                          
忽略:10 https://download.docker.com/linux/ubuntu focal InRelease             
获取:11 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages [11.0 kB]
错误:12 https://download.docker.com/linux/ubuntu focal Release                  
  404  Not Found [IP: 13.225.103.32 443]
正在读取软件包列表... 完成                                                                                                                                                                                  
E: 仓库 “https://download.docker.com/linux/ubuntu focal Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。

可以看到的是,上面的 11 已经是成功的,12 是错误的,这个时候,我们只需要其 /etc/apt/source.list 中删除掉报错对应的内容

再次更新源

sudo apt-get update

安装最新的 docker-ce

sudo apt-get install docker-ce

避免每次使用 docker 命令都需要加上 sudo

sudo usermod -a -G docker $USER
or
sudo usermod -aG docker $USER

重启系统

posted @ 2020-05-01 08:34  高方也  阅读(10176)  评论(2编辑  收藏  举报