记录docker-ce安装过程,全过程主要以官网上提供的方法进行操作。
1 在centos8.8版本上部署docker-ce(参照官方文档部署)
第一步:确认操作系统版本是centos8,执行cat /etc/centos-release
查看操作系统版本
[root@localhost ~]# cat /etc/centos-release CentOS Linux release 8.0.1905 (Core)
第二步:检查系统中是否有docker包或docker-engine,执行yum repolist
查看。 官方文档中说明,若存在docker或docker-engine,可通过如下命令删除:
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
第三步:安装yum-utils(yum-utils提供yum-config-manager),在安装docker之前,需要安装容器仓库(Docker repository),官方文档提供两种方式安装,一种是安装yum-utils,二是安装yum-config-manager。
$ sudo yum install -y yum-utils
#下面的命令默认操作系统支持yum-config-manager
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
扩展-该步骤常见问题
该步骤出现的错误1:
[root@localhost yum.repos.d]# yum repolist
Failed to set locale, defaulting to C
原因分析:没有配置正确的语言环境导致的提示。
解决方法:执行以下语句修改语言环境。
echo "export LC_ALL=en_US.UTF8" >> /etc/profile
source /etc/profile
该步骤出现的错误2:
[root@localhost yum.repos.d]# yum repolist
CentOS-8 AppStream 24 B/s \| 38 B 00:01
CentOS-8 - Base 24 B/s \| 38 B 00:01
Failed to synchronize cache for repo 'AppStream', ignoring this repo.
Failed to synchronize cache for repo 'BaseOS', ignoring this repo.
原因分析:yum源配置有问题,读不到相关数据。
解决方法:替换/etc/yum.repos.d/Centos-Base.repo和/etc/yum.repos.d/Centos-AppStream.repo中yum源信息。 修改Centos-Base.repo中信息如下,将baseurl替换成aliyun: baseurl=https://mirrors.aliyun.com/centos/8-stream/BaseOS/$basearch/os/
修改Centos-AppStream.repo中信息如下,将baseurl替换成aliyun: baseurl=https://mirrors.aliyun.com/centos/8-stream/AppStream/$basearch/os/
第四步:安装docker-engine
#执行
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
扩展-该步骤常见问题
该步骤会报错,大致信息如下:
Error:
Problem 1: problem with installed package podman-1.0.0-2.git921f98f.module_el8.0.0+58+91b614e7.x86_64
Problem 2: package buildah-1.19.8-1.module_el8.5.0+733+9bb5dffa.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
(try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
解决方法:根据提示信息可以得知这是由于docker和podman包冲突了,并提供三种解决方法,此处我们选择—allowerasing移除podman的包,使用docker的包。
重新执行yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin --allowerasing`
第五步:启动docker服务
#启动docker
systemctl start docker
#启动完成后检查docker是否启动
执行systemctl status docker检查服务是否启动
[root@localhost yum.repos.d]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2022-05-25 08:57:08 CST; 1min 39s ago
Docs: https://docs.docker.com
Main PID: 809 (dockerd)
Tasks: 7
Memory: 111.1M
CGroup: /system.slice/docker.service
└─809 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
第六步:进行hello world测试
#利用hello world镜像做测试
docker run hello-world #需要连网