CentOS7下安装Docker

检查是否存在旧版本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 命令启动或关闭。

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值