在 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

重啟系統


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM