官方文檔:https://docs.docker.com/engine/install/ubuntu/
01
卸載舊版本Docker
docker的舊版本稱為docker伦意、docker.io或docker engine。如果已安裝這些,請卸載它們:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
如果apt-get報告沒有安裝這些軟件包漆诽,那也沒有關(guān)系尼桶。
02
安裝Docker
1侄非、更新apt包索引睡扬,安裝包以允許apt通過 HTTPS 使用存儲庫
Update the apt package index and install packages to allow apt to use arepository over HTTPS:
$ sudo apt-get update
$ sudo apt-get install ca-certificates curl gnupg lsb-release apt-transport-https
2谬哀、添加Docker官方的GPG密鑰
Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
3比吭、設(shè)置穩(wěn)定存儲庫
Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below. Learn about nightly and test channels.
$ 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
4绽族、更新apt包索引,安裝最新版本的Docker Engine和containerd
Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
5衩藤、運行hello-world 鏡像驗證Docker Engine是否已正確安裝
$ sudo docker run hello-world
6吧慢、檢測docker版本信息
$ docker --version
輸出以下內(nèi)容:
Docker version 20.10.11, build dea9396
03
安裝過程中出現(xiàn)的錯誤并解決
1、錯誤1:
執(zhí)行以下指令:
$ sudo apt-get update
報錯:
Hit:1 http://mirrors.tencentyun.com/ubuntu bionic InRelease
Get:2 http://mirrors.tencentyun.com/ubuntu bionic-security InRelease [88.7 kB]? ? ? ? ? ? ? ? ? ? ??
Get:3 http://mirrors.tencentyun.com/ubuntu bionic-updates InRelease [88.7 kB]
Ign:4 https://download.docker.com/linux/ubuntu \ InRelease
Err:5 https://download.docker.com/linux/ubuntu \ Release
? 404? Not Found [IP: 18.65.191.34 443]
Reading package lists... Done
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.
忽略赏表,繼續(xù)執(zhí)行下一條指令:
$ 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 sourceE: 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'
還是報錯检诗,沒有辦法繼續(xù)。
解決辦法:
編輯ubuntu源 /etc/apt/source.list
$ sudo cp /etc/apt/source.list /etc/apt/source.list.back
$ sudo vi /etc/apt/source.list
在頁尾增加以下內(nèi)容:
deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable
重新執(zhí)行安裝指令:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
2瓢剿、錯誤2:
當添加新的源后逢慌,進行apt-get update后,可能會出現(xiàn)以下問題:
Hit:1 http://mirrors.tencentyun.com/ubuntu bionic InRelease
Get:2 http://mirrors.tencentyun.com/ubuntu bionic-security InRelease [88.7 kB]? ? ? ? ? ? ? ? ? ??
Get:3 http://mirrors.tencentyun.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 https://download.docker.com/linux/ubuntu bionic InRelease [64.4 kB]? ? ? ? ? ? ? ? ?
Err:4 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
Ign:5 https://download.docker.com/linux/ubuntu \ InRelease
Err:6 https://download.docker.com/linux/ubuntu \ Release
? 404? Not Found [IP: 18.65.191.124 443]
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.
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.
解決辦法:
將公鑰添加至服務(wù)器间狂,即終端中輸入:
$ 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
重新執(zhí)行安裝指令:
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
問題解決攻泼,繼續(xù)下一步安裝。