【Docker】Ubuntu 18.04 安裝Docker

官方文檔: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)系尼桶。

卸載舊版本docker

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

安裝包以允許apt通過 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

添加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 source

E: 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ù)下一步安裝。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末前标,一起剝皮案震驚了整個濱河市坠韩,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌炼列,老刑警劉巖只搁,帶你破解...
    沈念sama閱讀 221,820評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異俭尖,居然都是意外死亡氢惋,警方通過查閱死者的電腦和手機洞翩,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,648評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來焰望,“玉大人骚亿,你說我怎么就攤上這事⌒芾担” “怎么了来屠?”我有些...
    開封第一講書人閱讀 168,324評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長震鹉。 經(jīng)常有香客問我俱笛,道長,這世上最難降的妖魔是什么传趾? 我笑而不...
    開封第一講書人閱讀 59,714評論 1 297
  • 正文 為了忘掉前任迎膜,我火速辦了婚禮,結(jié)果婚禮上浆兰,老公的妹妹穿的比我還像新娘磕仅。我一直安慰自己,他們只是感情好簸呈,可當我...
    茶點故事閱讀 68,724評論 6 397
  • 文/花漫 我一把揭開白布榕订。 她就那樣靜靜地躺著,像睡著了一般蝶棋。 火紅的嫁衣襯著肌膚如雪卸亮。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,328評論 1 310
  • 那天玩裙,我揣著相機與錄音,去河邊找鬼段直。 笑死吃溅,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的鸯檬。 我是一名探鬼主播决侈,決...
    沈念sama閱讀 40,897評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼喧务!你這毒婦竟也來了赖歌?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,804評論 0 276
  • 序言:老撾萬榮一對情侶失蹤功茴,失蹤者是張志新(化名)和其女友劉穎庐冯,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體坎穿,經(jīng)...
    沈念sama閱讀 46,345評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡展父,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,431評論 3 340
  • 正文 我和宋清朗相戀三年返劲,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片栖茉。...
    茶點故事閱讀 40,561評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡篮绿,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出吕漂,到底是詐尸還是另有隱情亲配,我是刑警寧澤,帶...
    沈念sama閱讀 36,238評論 5 350
  • 正文 年R本政府宣布惶凝,位于F島的核電站弃榨,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏梨睁。R本人自食惡果不足惜鲸睛,卻給世界環(huán)境...
    茶點故事閱讀 41,928評論 3 334
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望坡贺。 院中可真熱鬧官辈,春花似錦、人聲如沸遍坟。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,417評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽愿伴。三九已至肺魁,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間隔节,已是汗流浹背鹅经。 一陣腳步聲響...
    開封第一講書人閱讀 33,528評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留怎诫,地道東北人瘾晃。 一個月前我還...
    沈念sama閱讀 48,983評論 3 376
  • 正文 我出身青樓,卻偏偏與公主長得像幻妓,于是被迫代替她去往敵國和親蹦误。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,573評論 2 359

推薦閱讀更多精彩內(nèi)容