1 centos7下安装docker的正确姿势
安装docker的三个前提:
1)Docker 要求 CentOS 系统的内核版本高于 3.10 ,使用uname -r 命令查看
[root@mz-01 ~]# uname -r
3.10.0-514.el7.x86_64
2) centos-extras库必须启用,这个存储库默认启用,但是如果您禁用了它,您需要重新启用它。使用 "vim /etc/yum.repos.d/CentOS-Base.repo"命令
[root@mz-01 ~]# vim /etc/yum.repos.d/CentOS-Base.repo
CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
enabled=1 ★ 値从0变成1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
3)卸载旧版本
[root@mz-01 ~]# sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
1.1 安装需要的依赖包
[root@mz-01 ~]# yum install -y yum-utils device-mapper-persistent-data
1.2 配置稳定仓库
[root@mz-01 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
1.3 安装
[root@mz-01 ~]# yum install docker-ce
1.4 启动docker
[root@mz-01 ~]# systemctl start docker
[root@mz-01 ~]# systemctl enable docker #开机自启动
1.5 验证docker是否安装正确
[root@mz-01 ~]# docker run hello-world
2 如何配置国内镜像
2.1 登录阿里开发者平台
阿里开发者平台的url地址:https://dev.aliyun.com/search.html,有账号的直接登录,没账号的注册成功后登录,登录成功后出现如下界面:
2.2 点击“创建我的容器镜像”
点击“确认”即可。
2.3 点击“镜像加速器”
2.4 配置镜像加速器地址
如果我们没有/etc/docker/daemon.json这个文件,我们可以采用下面的方式来配置:
修改配制文件 : vim usr/lib/systemd/system/docker.service
添加红色部分到 "ExecStart":ExecStart=/usr/bin/dockerd --registry-mirror=your accelerate address
保存文件
重新加载配置:$ systemctl daemon-reload
重新启动服务:$ service docker restart