ubuntu20.04 官方文檔 安裝docker前言
今天查閱dokcer
的issue
時發現ubuntu20.04
安裝docker的步驟已經解決,只是官方目前沒有修改官方文檔
之前之所以不能按照官方文檔安裝下去是因爲文檔中這一句
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
這一句會獲取當前ubuntu
系統的別名與docker
的鏈接,匹配相應系統支持的docker
版本,但是運行了你會發現ubuntu20.04
的別名focal
在那個鏈接中找不到。
在此之前,折中的辦法是使用ubuntu19.10
的eoan
別名下載docker
並安裝。
現在,docker
已經有focal
的鏈接了。於是我們可以正常按照官方文檔的步驟安裝
文檔地址:https://docs.docker.com/engine/install/ubuntu/
卸載老舊的docker版本
Older versions of Docker were called
docker
,docker.io
, ordocker-engine
. If these are installed, uninstall them:
ubuntu
自帶的apt
安裝的docker
是很古老的版本,所以如果看到哪些博主在2020年使用這個命令安裝docker
,可以哂笑一下
如果之前安裝了老版本的docker
先卸載
sudo apt-get remove docker docker-engine docker.io containerd runc
安裝依賴
Update the
apt
package index and install packages to allowapt
to use a repository over HTTPS:
更新軟件源,安裝依賴
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加GPG key
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
安裝上了一般就行了,不用驗證
Verify that you now have the key with the fingerprint
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
, by searching for the last 8 characters of the fingerprint.
如果要驗證的話
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) <[email protected]>
sub rsa4096 2017-02-22 [S]
添加源
Use the following command to set up the stable repository.
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
這一步驟官方已經完善了,以前是報錯的。現在按命令行安裝即可
安裝docker
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
驗證docker
Verify that Docker Engine is installed correctly by running the
hello-world
image.
sudo docker run hello-world
非root用戶使用docker
這一步比較重要
sudo usermod -aG docker youubuntuname
將你在ubuntu使用的用戶名替換掉youubuntuname即可
驗證:
cat /etc/group | grep docker
比如我的用戶是mrcangye
顯示:
docker:x:135:mrcangye
以後使用docker就可以不加sudo了,方便又安全
查看docker版本
docker --version
顯示:
Docker version 19.03.9, build 9d988398e7
docker信息
docker system info
會顯示大段的docker信息
修改docker鏡像
優先使用國內的阿里雲docker鏡像,目前阿里雲在雲上的支持是遠遠領先於國內其他家雲服務商的,無可爭議
打開以下鏈接登陸阿里雲,阿里雲會給你一個docker鏡像加速地址。按阿里雲要求去做即可
例如
針對Docker客戶端版本大於 1.10.0 的用戶
您可以通過修改daemon配置文件/etc/docker/daemon.json來使用加速器
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://bmtb46e4.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
上面命令是讓我們修改/etc/docker/daemon.json
文件
將文件內容改爲:
{
"registry-mirrors": ["https://bmtb46e4.mirror.aliyuncs.com"]
}
再重啓docker服務