在阿里云服务器上安装Docker的步骤如下,以CentOS和Ubuntu为例:
在CentOS上安装Docker
• 更新软件包
```bash
sudo yum update -y
```
• 卸载旧版Docker
```bash
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
```
• 安装必要的依赖
```bash
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
```
• 设置Docker镜像源(阿里云源)
```bash
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
```
• 更新yum缓存
```bash
sudo yum makecache fast
```
• 安装Docker
```bash
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```
• 启动Docker服务并设置开机自启
```bash
sudo systemctl start docker
sudo systemctl enable docker
```
• 验证Docker是否安装成功
```bash
sudo docker version
sudo docker run hello-world
```
在Ubuntu上安装Docker
• 更新软件包
```bash
sudo apt update && sudo apt upgrade -y
```
• 卸载旧版Docker
```bash
sudo apt-get remove docker docker-engine docker.io containerd runc
```
• 安装必要的依赖
```bash
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
```
• 添加Docker的官方GPG密钥
```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
```
• 添加Docker的APT软件仓库
```bash
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
```
• 更新APT软件包索引
```bash
sudo apt update
```
• 安装Docker引擎
```bash
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
```
• 启动Docker服务并设置开机自启
```bash
sudo systemctl start docker
sudo systemctl enable docker
```
• 验证Docker是否安装成功
```bash
sudo docker version
sudo docker run hello-world
```
配置Docker镜像加速
为了提高Docker镜像的下载速度,可以配置阿里云的镜像加速器:
• 创建或编辑Docker配置文件
```bash
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://rpu0hzw5.mirror.aliyuncs.com"]
}
EOF
```
• 重新加载Docker守护进程配置并重启Docker服务
```bash
sudo systemctl daemon-reload
sudo systemctl restart docker
```
通过以上步骤,您可以在阿里云服务器上成功安装并配置Docker,确保Docker能够高效地运行和管理容器。