以下是基于国内镜像站的完整步骤。以 中科大镜像源 为例,整个过程需要依次执行多个命令。

  1. 清理旧版本:如果之前安装过Docker,建议先卸载,以避免潜在的冲突。

    sudo apt-get remove docker docker-engine docker.io containerd runc
    
  2. 安装基础依赖:安装一些必要的工具包,以便系统能通过HTTPS使用软件仓库。

    sudo apt-get update
    sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
    
  3. 添加Docker的官方GPG密钥:这一步用于验证软件包的完整性。

    curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
    
  4. 添加Docker软件仓库这是解决你报错问题的关键步骤。此命令会将中科大的Docker CE仓库地址添加到你的系统源列表中。

    sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
    
  5. 安装Docker CE:添加仓库后,更新源并安装。

    sudo apt-get update
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io
    
  6. 验证安装:安装完成后,运行一个测试镜像来确认一切正常。

    sudo systemctl start docker
    sudo docker ps
    
  7. 更换镜像源:安装完成后,运行一个测试镜像来确认一切正常。

    sudo tee /etc/docker/daemon.json <<-'EOF'
    	{
    	"registry-mirrors": [
    	"https://docker.mirrors.ustc.edu.cn/",
    	"https://docker.m.daocloud.io",
    	"https://docker.nju.edu.cn"
    	]
    	}
    	EOF
    
  8. 重启 Docker 服务使配置生效

    sudo systemctl daemon-reload
    sudo systemctl restart docker
    
Logo

码道开发者社区,聚焦华为云码道 CodeArts 代码智能体,沉淀 Agent、Skill、鸿蒙开发实战内容,供开发者查阅资料、交流技术、分享工程实践

更多推荐