CentOS7安装docker

Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE。

一、安装Docker

1、Docker要求Centos系统的内核高于3.10,通过 uname -r 命令查看你当前的内核版本

[root@localhost ~]# uname -r

2、确保 yum 包更新到最新。

[root@localhost ~]# yum -y update

3、卸载旧版本(如果安装过旧版本的话)

[root@localhost ~]# yum remove docker  docker-common docker-selinux docker-engine

4、安装需要的软件包

[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2

5、设置yum源

[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
会报以下错误

已加载插件:fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
Could not fetch/save url https://download.docker.com/linux/centos/docker-ce.repo to file /etc/yum.repos.d/docker-ce.repo: [Errno 12] Timeout on https://download.docker.com/linux/centos/docker-ce.repo: (28, 'Operation timed out after 30001 milliseconds with 0 out of 0 bytes received')

这是由于国内访问不到docker官方镜像的缘故 
可以通过aliyun的源来完成:

[root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
出现以下内容则表示docker仓库配置成功:
已加载插件:fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

6、可以查看所有仓库中所有docker版本,并选择特定版本安装

[root@localhost ~]#  yum list docker-ce --showduplicates | sort -r
已加载插件:fastestmirror, langpacks
可安装的软件包
Loading mirror speeds from cached hostfile
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable

7、安装docker

[root@localhost ~]# yum install docker-ce   #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版18.03.1

8、启动并加入开机启动

[root@localhost ~]# systemctl start docker.service
[root@localhost ~]# systemctl enable docker.service

9、验证安装是否成功(有client和service两部分表示docker安装启动都成功了)

[root@localhost ~]# docker version
Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:20:16 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:23:58 2018
  OS/Arch:      linux/amd64
  Experimental: false

 二、Docker使用阿里云镜像

1、阿里云docker仓库https://dev.aliyun.com/search.html

2、进去注册帐号后,点击自己的管理中心。

3、在管理中心点击加速器,右边面板会有你的加速地址,右边面板下面有详细设置步骤。

这里以Centos为例:

通过修改daemon配置文件/etc/docker/daemon.json来使用加速器:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://bg7ubihe.mirror.aliyuncs.com"]  #修改为自己加速器地址
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
原文地址:https://www.cnblogs.com/liujinlei/p/9040771.html