溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

ubuntu怎么安裝docker

發(fā)布時(shí)間:2022-10-27 09:42:36 來(lái)源:億速云 閱讀:110 作者:iii 欄目:服務(wù)器

本篇內(nèi)容介紹了“ubuntu怎么安裝docker”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

零:卸載舊版本

docker 的舊版本被稱(chēng)為 docker,docker.io 或 docker-engine 。如果已安裝,請(qǐng)卸載它們:

$ sudo apt-get remove docker docker-engine docker.io containerd runc

當(dāng)前稱(chēng)為 docker engine-community 軟件包 docker-ce 。

一:設(shè)置倉(cāng)庫(kù)

在新主機(jī)上首次安裝 docker engine-community 之前,需要設(shè)置 docker 倉(cāng)庫(kù)。之后,您可以從倉(cāng)庫(kù)安裝和更新 docker 。

更新 apt 包索引。

$ sudo apt-get update

安裝 apt 依賴(lài)包,用于通過(guò)https來(lái)獲取倉(cāng)庫(kù):

$ sudo apt-get install \
 apt-transport-https \
 ca-certificates \
 curl \
 gnupg-agent \
 software-properties-common

添加 docker 的官方 gpg 密鑰:

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

9dc8 5822 9fc7 dd38 854a e2d8 8d81 803c 0ebf cd88 通過(guò)搜索指紋的后8個(gè)字符,驗(yàn)證您現(xiàn)在是否擁有帶有指紋的密鑰。

$ sudo apt-key fingerprint 0ebfcd88
 
pub rsa4096 2017-02-22 [scea]
  9dc8 5822 9fc7 dd38 854a e2d8 8d81 803c 0ebf cd88
uid   [ unknown] docker release (ce deb) <docker@docker.com>
sub rsa4096 2017-02-22 [s]

使用以下指令設(shè)置穩(wěn)定版?zhèn)}庫(kù)

注意:目前 20.04 還沒(méi)有國(guó)內(nèi) docker 源,暫時(shí)用 18.04 版本。

$ sudo add-apt-repository \
 "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
 bionic \
 stable"

二:安裝 docker engine-community

更新 apt 包索引。

$ sudo apt-get update

安裝最新版本的 docker engine-community 和 containerd

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

三:測(cè)試

輸入

$ sudo docker run hello-world

如果docker和你問(wèn)好——或者說(shuō)出現(xiàn)類(lèi)似以下輸出

unable to find image 'hello-world:latest' locally
latest: pulling from library/hello-world
1b930d010525: pull complete                                 digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
status: downloaded newer image for hello-world:latest


hello from docker!
this message shows that your installation appears to be working correctly.


to generate this message, docker took the following steps:
 1. the docker client contacted the docker daemon.
 2. the docker daemon pulled the "hello-world" image from the docker hub.
 (amd64)
 3. the docker daemon created a new container from that image which runs the
 executable that produces the output you are currently reading.
 4. the docker daemon streamed that output to the docker client, which sent it
 to your terminal.


to try something more ambitious, you can run an ubuntu container with:
 $ docker run -it ubuntu bash


share images, automate workflows, and more with a free docker id:
 https://hub.docker.com/


for more examples and ideas, visit:
 https://docs.docker.com/get-started/

就說(shuō)明安裝完事了。

四:免sudo運(yùn)行&鏡像加速

免sudo

參考如下方法將用戶添加到docke組

$ sudo usermod -ag docker [你的用戶名]

重啟docker

$ sudo systemctl restart docker

(然而我的機(jī)器上發(fā)生了很詭異的事——我重啟docker服務(wù)后依然不能以普通用戶啟動(dòng)docker。重啟機(jī)器后才能免sudo運(yùn)行。)

docker鏡像加速

我用了阿里云的免費(fèi)加速

“ubuntu怎么安裝docker”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI