ubuntu20.04 官方文档 安装docker

举报
陈沧夜 发表于 2022/04/29 23:01:53 2022/04/29
3.1k+ 0 0
【摘要】 ubuntu20.04 官方文档 安装docker前言 今天查阅dokcer的issue时发现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) <docker@docker.com>
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服务

文章来源: blog.csdn.net,作者:沧夜2021,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/CANGYE0504/article/details/106213641

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。