安装
# CentOS
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 &&
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo &&
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo &&
sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo &&
sudo yum makecache fast &&
sudo dnf makecache &&
sudo yum -y install docker-ce && docker -v && systemctl enable docker && systemctl restart docker
# Ubuntu
sudo apt-get remove docker docker-engine docker.io containerd runc &&
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common &&
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg &&
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null &&
sudo apt-get update && sudo apt-get install -y docker-ce && docker -v && systemctl enable docker && systemctl restart docker
# docker-compose
curl -L "https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose &&
chmod +x /usr/local/bin/docker-compose &&
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose &&
docker-compose -v
正常
#!/bin/bash
##安装依赖
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
##安装Docker官方GPG证书
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
##安装阿里云GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
##Docker官方仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
##阿里云仓库
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
##更新并安装Docker-CE
sudo apt-get -y update && sudo apt-get install -y docker-ce
#启动docker
systemctl start docker && systemctl enable docker
#添加阿里云镜像加速
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://pngamxmy.mirror.aliyuncs.com"],
"live-restore": true,
"log-driver": "json-file",
"log-opts": {
"max-file": "3",
"max-size": "100m"
}
}
EOF
##重新加载配置和重启docker
systemctl daemon-reload && systemctl restart docker
##软连接docker-compose
ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin/docker-compose
##版本信息
docker-compose --version
卸载
yum remove docker-ce docker-ce-cli containerd.io &&
rm -rf /var/lib/docker &&
rm -rf /var/lib/containerd