ubuntu20.04 官方文档 安装docker

ubuntu20.04 官方文档 安装docker前言

今天查阅dokcerissue时发现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.10eoan别名下载docker并安装。

现在,docker已经有focal的链接了。于是我们可以正常按照官方文档的步骤安装

文档地址:https://docs.docker.com/engine/install/ubuntu/

卸载老旧的docker版本

Older versions of Docker were called docker, docker.io, or docker-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 allow apt 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服务

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章