Linux安装docker
docker安装
安装流程
1.安装docker环境依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
2.配置阿里云yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3.安装docker
yum -y install docker-ce doker-ce-cli containerd.io
4.启动Docker服务并设置为开机自启
systemctl start docker
systemctl enable docker
linux安装docker Shell脚本
下面展示一些 内联代码片
。
#!/bin/bash
# 检查Docker是否已经安装
if systemctl is-active --quiet docker; then
echo "Docker is already running. Stopping and uninstalling it..."
# 停止Docker服务
sudo systemctl stop docker
# 卸载Docker
sudo yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
# 清理Docker相关的yum缓存
sudo yum clean all
sudo rm -rf /var/lib/docker
fi
# 安装Docker所需的依赖包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 设置Docker的官方仓库
sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 安装Docker CE
sudo yum install -y docker-ce docker-ce-cli containerd.io
# 启动Docker服务并设置为开机自启
sudo systemctl start docker
sudo systemctl enable docker
# 验证Docker安装是否成功
docker version
echo "Docker installation completed successfully!"