Ubuntu20下载安装Docker
阅读原文时间:2023年07月11日阅读:1
  • 卸载旧版本

    sudo apt-get remove docker <br /> docker-engine <br /> docker.io

  • 使用apt安装

    sudo apt-get update

    sudo apt-get install <br /> apt-transport-https <br /> ca-certificates <br /> curl <br /> gnupg <br /> lsb-release

  • 添加软件源GPG秘钥

    curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

  • 添加docker软件源

    echo <br /> "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu <br /> $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

  • 安装Docker

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

  • 启动Docker

    sudo systemctl enable docker
    sudo systemctl start docker

  • 建立用户组并将当前用户加入docker组

    sudo groupadd docker #添加docker组
    sudo usermod -aG docker $USER #将当前用户加入docker组

  • 测试Docker是否安装正确

    docker run --rm hello-world

重要:设置Docker镜像加速

  • 查看是否为docker.service中配置过镜像地址

    systemctl cat docker | grep '--registry-mirror'

  • 具体配置如下:在/etc/docker/daemon.json中写入以下内容

    {
    "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com"
    ]
    }

  • 重启服务

    sudo systemctl daemon-reload
    sudo systemctl restart docker

  • 使用docker info查看加速器是否生效

    Registry Mirrors:
    https://hub-mirror.c.163.com/

    sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin
    sudo rm -rf /var/lib/docker
    sudo rm -rf /var/lib/containerd