更新Ubuntu:
sudo apt-get update
添加Docker库信息:
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
运行下列命令添加Docker官方GPG密钥:
sudo curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.ascsudo chmod a+r /etc/apt/keyrings/docker.ascecho \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
使用命令更新ubuntu列表:
sudo apt update
安装docker:
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
安装完成后,运行如下命令验证Docker服务是否正常运行:
sudo systemctl status docker
结果应该是这样:
设置docker服务每次重启时自启动:
sudo systemctl enable docker
查看docker版本:
sudo docker version
测试docker:
sudo docker run hello-world
出错了:
error pulling image configuration: download failed after attempts=6: dial tcp 108.160.166.42:443: connect: connection refused. See 'docker run --help'.
纠错:
试试这个:
sudo mkdir -p /etc/dockersudo tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://do.nark.eu.org","https://dc.j8.work","https://docker.m.daocloud.io","https://dockerproxy.com","https://docker.mirrors.ustc.edu.cn","https://docker.nju.edu.cn"]
}
EOFsudo systemctl daemon-reload
sudo systemctl restart docker
重新执行:
sudo docker run hello-world
成功: