Ubuntu 20.04 (LTS)安装Docker—且配置阿里镜像加速(使用阿里云文档方式添加)

首先报上官网地址当然一下顺序也是大体按照官网方式进行的
Ubuntu安装Docker Docs

环境条件:

  • Ubuntu Impish 21.10
  • Ubuntu Hirsute 21.04
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)

Docker Engine is supported on x86_64 (or amd64), armhf, arm64, and s390x architectures.

卸载旧版本

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

如果apt-get报告没有安装这些软件包,没关系。

# 以下是没有安装这些软件包的报告
root@azang405:~# sudo apt-get remove docker docker-engine docker.io containerd runc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package docker
E: Unable to locate package docker-engine
E: Unable to locate package docker.io
E: Couldn't find any package by glob 'docker.io'
E: Couldn't find any package by regex 'docker.io'
E: Unable to locate package containerd
E: Unable to locate package runc

/var/lib/docker/的内容,包括图像、容器、卷和网络,将被保留。如果您不需要保存现有数据,并希望从干净的安装开始

# 卸载Docker Engine
# 卸载Docker引擎、CLI和容器包:

$ sudo apt-get purge docker-ce docker-ce-cli containerd.io
# 主机上的图像、容器、卷或自定义配置文件不会自动删除。要删除所有图像、容器和卷:

$ sudo rm -rf /var/lib/docker
$ sudo rm -rf /var/lib/containerd

更新仓库

  1. 更新apt包索引并安装包以允许apt通过 HTTPS 使用存储库:

     sudo apt-get update
     sudo apt-get install \
        ca-certificates \
        curl \
        gnupg \
        lsb-release
    
  2. 添加Docker官方的GPG密钥:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    
  3. 使用以下命令设置稳定存储库。要添加 夜间测试存储库,请在以下命令中的单词后添加单词nightlytest(或两者都要)在stable单词之后
    具体三种单词的区别在命令行代码之后有图,这里是用的是chrome浏览器进行的翻译,同时这里附上链接可以自己去查看一下官网文档

    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
    

    在这里插入图片描述

安装Docker引擎

  1. 更新apt包索引,安装最新版本的Docker Engine和containerd,或者到下一步安装特定版本:

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

接下来查看是否安装成功!

root@azang405:~# docker -v
Docker version 20.10.10, build b485636

配置阿里镜像源

  • 首先去阿里云官网注册一下账号,然后登陆
    接下来点击控制台选择镜像
    在这里插入图片描述
  • 然后点击进入
    在这里插入图片描述
  • 接下来复制对应的命令到你的shell中
    也就是下方的框起来的地方
    在这里插入图片描述
    执行对应的命令
root@azang405:~# docker run -it hello-world

# 这里可以看到hello 完活
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/