卸载旧版本

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

使用 APT 安装(建议使用)

  1. # 更新数据源
  2. apt-get update
  3. # 安装所需依赖
  4. apt-get -y install apt-transport-https ca-certificates curl software-properties-common
  5. # 安装 GPG 证书
  6. curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
  7. # 新增数据源
  8. add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  9. # 更新并安装 Docker CE
  10. apt-get update && apt-get install -y docker-ce

使用脚本安装

  1. # 下载脚本文件
  2. curl -fsSL get.docker.com -o get-docker.sh
  3. # 启动脚本
  4. sh get-docker.sh --mirror Aliyun

镜像加速(阿里)

注: 国内镜像加速器可能会很卡,请替换成你自己阿里云镜像加速器,地址如:https://yourself.mirror.aliyuncs.com,在阿里云控制台的 容器镜像服务 -> 镜像加速器 菜单中可以找到

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://rp9zscnl.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://hub-mirror.c.163.com/"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker