docker 安装(一)
docker安装有两种方式:
- 手动安装
- 脚本安装
手动安装
①查询是否安装过docker:
yum list installed | grep docker*
②卸载已安装
yum remove 卸载docker包
③安装工具包
yum install -y yum-utils device-mapper-persistent-data lvm2
注意:上面可能出现仓库找不到的错误,可以修改仓库中的镜像地址
cd /etc/yum.repos.d/
清除对应的仓库:rm -rf 仓库
yum clean all 清除仓库元数据
yum makecache 刷新元数据缓存
③添加仓库:
官方源地址:
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
阿里仓库:
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
清华大学源:
yum-config-manager \
--add-repo \
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
④安装dockek-ce
- yum makecache timer(可选,因为加入了新的仓库地址,可先缓存至本地)
- 查看docker版本:
yum list docker-ce.x86_64 --showduplicates | sort -r
- 安装docker:
yum install docker-ce-<版本号>
- 启动docker
systemctl start docker
- 开机启动
systemctl enable docker
- 测试
docker run hello-world
脚本安装
①下载脚本
curl -fsSL get.docker.com -o get-docker.sh
②删除系统自带的容器工具:podman buildah
yum remove podman buildah
③执行脚本
sh get-docker.sh
④docker启动 =>开机启动 => 测试
同上