下载
中文
注册

部署Docker(Ubuntu)

前提条件

  • 配置源之前,请确保安装环境能够连接网络。
  • 请在root用户下执行如下命令检查源是否可用。
    apt-get update

    如果命令执行报错或者后续安装依赖时等待时间过长甚至报错,则参考如下方式解决:

    • 请在“/etc/apt/sources.list”文件中的检查源是否正确,如果没有配置源,请配置可用的源。
    • 用户也可以登录源链接,根据现场操作系统架构和版本,进入对应操作系统目录,单击打开“source.list”文件,将文件内源链接复制到服务器“/etc/apt/sources.list”文件中,要包含Docker-ce相关的源,再执行apt-get update命令。

安装Docker

  1. root用户登录服务器,配置信任Docker的GPG公钥,命令如下:
    curl -fsSL https://repo.huaweicloud.com/docker-ce/linux/debian/gpg | sudo apt-key add -
  2. 执行以下命令,更新源并安装Docker。
    apt-get update
    apt-get install docker-ce

    如果执行apt-get update命令时,出现类似如下所示报错,则执行apt-get update --allow-unauthenticated命令。

    Err:1 https://repo.huaweicloud.com/docker-ce/linux/ubuntu focal InRelease  Temporary failure resolving 'repo.huaweicloud.com'
    Err:2 https://mirrors.huaweicloud.com/ubuntu-ports focal InRelease  Temporary failure resolving 'mirrors.huaweicloud.com'
    Err:3 https://mirrors.huaweicloud.com/ubuntu-ports focal-updates InRelease Temporary failure resolving 'mirrors.huaweicloud.com'
    Err:4 https://mirrors.huaweicloud.com/ubuntu-ports focal-security InRelease Temporary failure resolving 'mirrors.huaweicloud.com'
    Err:5 https://mirrors.huaweicloud.com/docker-ce/linux/ubuntu focal InRelease Temporary failure resolving 'mirrors.huaweicloud.com'
    Reading package lists... Done
    N: Ignoring file 'index.html' in directory '/etc/apt/sources.list.d/' as it has an invalid filename extension
    W: Failed to fetch https://mirrors.huaweicloud.com/ubuntu-ports/dists/focal/InRelease  Temporary failure resolving 'mirrors.huaweicloud.com'
    W: Failed to fetch https://mirrors.huaweicloud.com/ubuntu-ports/dists/focal-updates/InRelease  Temporary failure resolving 'mirrors.huaweicloud.com'
    W: Failed to fetch https://mirrors.huaweicloud.com/ubuntu-ports/dists/focal-security/InRelease  Temporary failure resolving 'mirrors.huaweicloud.com'
    W: Failed to fetch https://mirrors.huaweicloud.com/docker-ce/linux/ubuntu/dists/focal/InRelease  Temporary failure resolving 'mirrors.huaweicloud.com'
    W: Failed to fetch https://repo.huaweicloud.com/docker-ce/linux/ubuntu/dists/focal/InRelease  Temporary failure resolving 'repo.huaweicloud.com'
    W: Some index files failed to download. They have been ignored, or old ones used instead.
  3. 执行systemctl start docker命令启动Docker。
  4. 执行docker version命令查看Docker是否已启动,如显示以下信息表示Docker已安装并启动。
    Client: Docker Engine - Community
     Version:           20.10.7
     API version:       1.41
     Go version:        go1.18.7
     Git commit:        baeda1f
     Built:             Tue Oct 30 19:55:49 2021
     OS/Arch:           linux/arm64
     Context:           default
     Experimental:      true
    
    Server: Docker Engine - Community
     Engine:
      Version:          20.10.7
      API version:      1.41 (minimum version 1.12)
      Go version:       go1.13.8
      Git commit:       20.10.7-Oubuntu5~18.04.3
      Built:            Fri Oct 22 19:54:13 2021
      OS/Arch:          linux/arm64
      Experimental:     false
     containerd:
      Version:          1.6.10
      GitCommit:        770bd0108c32f3fb5c73ae1264f7e503fe7b2661
     runc:
      Version:          1.1.4
      GitCommit:        v1.1.4-0-g5fd4c4d
     docker-init:
      Version:          0.19.0
      GitCommit:        de40ad0