安装Docker
- 卸载旧版本
sudo apt-get remove docker /
docker-engine /
docker.io
- 使用apt安装
sudo apt-get update
sudo apt-get install /
apt-transport-https /
ca-certificates /
curl /
gnupg /
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 /
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu /
$(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/
卸载Docker
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
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/281772.html