检查是否存在旧版本Docker,如若存在,卸之
方法一 (检查删除):
[root@iz2ze6otfin4hehdcng39hz ~]# yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
方法二 (确定目标删除):
#停止docker
[root@iz2ze6otfin4hehdcng39hz ~]# systemctl stop docker
#卸载
[root@iz2ze6otfin4hehdcng39hz ~]# yum -y remove docker-ce
#删除docker安装目录
[root@iz2ze6otfin4hehdcng39hz ~]# rm -rf /var/lib/docker
总之,删除干净即可。
安装软gcc
1)安装gcc
yum -y install gcc
2)安装 gcc-c++
yum -y install gcc-c++
3)检查gcc安装成功否(出现版本号即安装成功)
gcc -v
安装必须软件包
1) device-mapper-persistent-data和lvm2用于储存设备映射1
[root@iz2ze6otfin4hehdcng39hz ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
2) 配置一个稳定(stable)的仓库,仓库配置会保存到/etc/yum.repos.d/docker-ce.repo文件中。
[root@iz2ze6otfin4hehdcng39hz ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新软件包索引
[root@iz2ze6otfin4hehdcng39hz ~]# yum makecache fast
安装DOCKER CE
[root@iz2ze6otfin4hehdcng39hz ~]# yum -y install docker-ce
启动Docker
[root@iz2ze6otfin4hehdcng39hz ~]# systemctl start docker
查看docker版本
[root@iz2ze6otfin4hehdcng39hz ~]# docker version
测试 hello-world (首次会下载对应镜像)
[root@iz2ze6otfin4hehdcng39hz ~]# docker run hello-world
配置镜像加速
1 )阿里云镜像加速器
[root@iz2ze6otfin4hehdcng39hz ~]# mkdir -p /etc/docker
[root@iz2ze6otfin4hehdcng39hz ~]# vim /etc/docker/daemon.json
在文件中添加如下配置:
{"registry-mirrors": ["http://hub-mirror.c.163.com"] }
[root@iz2ze6otfin4hehdcng39hz ~]# systemctl daemon-reload
[root@iz2ze6otfin4hehdcng39hz ~]# systemctl restart docker
2)配置完成之后重启可能会报错:Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details;
是因为后缀名影响的,所以我们需要在对应目录(/etc/docker/)下修改配置文件后缀名
[root@iz2ze6otfin4hehdcng39hz docker]# mv daemon.json daemon.conf
3)修改完后重启
[root@iz2ze6otfin4hehdcng39hz ~]# systemctl restart docker
4)检查Docker容器是否运行
[root@iz2ze6otfin4hehdcng39hz ~]# docker ps
显示下面列表即容器启动
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
拓展 : 在linux中,宿主机安装的应用程序大多数都可以通过 systemctl start/stop xxxxxx 命令启动或关闭。