基于ubuntu22.04

更新索引包

1
sudo apt update

安装设置仓库必须的工具

1
sudo apt update && sudo apt install -y ca-certificates curl gnupg lsb-release

安装HTTPS支持包

1
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common

添加软件源的GPG密钥

1
sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/aliyun-docker.gpg

添加Docker软件源

1
2
3
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/aliyun-docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装

1
2
sudo apt update
sudo apt install -y docker-ce

启动后台服务

1
2
3
sudo service docker start
sudo systemctl restart docker
sudo systemctl start docker

查看 Docker 服务状态

sudo systemctl status docker

开启自启动

1
sudo systemctl enable docker

将当前用户添加到 docker 用户组

1
2
3
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker

配置镜像加速

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
sudo mkdir -p /etc/docker && sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
         "https://docker.mirrors.ustc.edu.cn",
         "https://hub-mirror.c.163.com",
         "https://mirror.ccs.tencentyun.com",
         "https://registry.docker-cn.com",
         "https://reg-mirror.qiniu.com"
  ]
}
EOF

加载配置

1
sudo systemctl daemon-reload

重启docker-ce

1
sudo systemctl restart docker

查看加速配置是否生效

1
sudo docker info

正确的效果

以上省略 
Registry Mirrors: 
https://docker.mirrors.ustc.edu.cn/ 
https://hub-mirror.c.163.com/ 
https://mirror.ccs.tencentyun.com/ 
https://registry.docker-cn.com/ 
https://reg-mirror.qiniu.com/ 
Live Restore Enabled: false

创建软链接

1
sudo ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/bin/docker-compose

注意: /usr/libexec/docker/cli-plugins/docker-compose 通过 sudo docker info 查找

查看docker-compose版本

1
sudo docker-compose -v

卸载docker

即使报错,也能干净

1
2
3
4
5
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker  
sudo rm -rf /var/lib/containerd
sudo apt-get remove -y docker* containerd.io podman* runc && apt-get autoremove

其他问题

cd /etc/apt/sources.list.d/

删除与Docker 相关的文件,

sudo apt clean
sudo apt update