系列目录html
Docker从1.13版本以后采用时间线的方式做为版本号,分为社区版CE和企业版EE。linux
社区版是免费提供给我的开发者和小型团体使用的,企业版会提供额外的收费服务,好比通过官方测试认证过的基础设施、容器、插件等。docker
社区版按照stable和edge两种方式发布,每一个季度更新stable版本,如17.06,17.09;每月份更新edge版本,如17.09,17.10。json
1) Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。centos
经过 uname -r 命令查看你当前的内核版本socket
uname -r
须要注意的是如下命令均是在
root
帐户下执行的,若是是普通帐户有些命令则可能须要加上sudo
测试
2)执行 yum updateui
yum update非必选项,可是建议执行操做this
3)卸载旧版本docker阿里云
yum -y remove docker docker-common docker-selinux docker-engine
3)设置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #阿里云yum源
须要注意的是,目前(2019年3月)测试的时候,docker不设置阿里云镜像源也是能正常安装的,而且阿里云镜像源地址也可能会更改,因此以上地址可能会返回404,若是以上镜像源地址不存在也能够忽略这一步直接进行下一步.
4)查看全部仓库中全部docker版本,并选择特定版本安装
yum list docker-ce --showduplicates | sort -r
5)安装docker
yum install -y docker-ce #因为repo中默认只开启stable仓库,故这里安装的是最新稳定版17.12.0 yum install -y <FQPN> # 例如:sudo yum install docker-ce-17.12.0.ce
6)启动docker并加入开机自动启动
systemctl start docker systemctl enable docker
7)配置阿里云镜像加速
mkdir -p /etc/docker vi /etc/docker/daemon.json
添加如下内容
{"registry-mirrors": ["https://5f2jam6c.mirror.aliyuncs.com", "http://hub-mirror.c.163.com"] }
8)从新加载配置文件
systemctl reload docker
9)重启docker
systemctl restart docker
安装过程当中可能会出现的问题:
1.正在处理依赖关系 docker-ce-selinux >= 17.03.0.ce-1.el7.centos,它被软件包 docker-ce-17.03.0.ce-1.el7.centos.x86_64 须要
软件包 docker-ce-selinux 已经被 docker-ce-cli 取代,可是取代的软件包并未知足需求”
等一大串的问题
这时咱们须要经过 yum install 安装一个rpm包
经过这个地址咱们查看和咱们安装docker版本一直的rpm包
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
经过
yum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
问题解决
2.非root用户使用docker命令报错
以上咱们为了方便在安装过程当中使用的是root帐户,然而实际操做中咱们可能更多的是用普通用户操做docker命令.从root用户切到普通用户执行docker命令时会报以下错误
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied
官方解释以下:
The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user. To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
sudo groupadd docker
此步骤并不是必须,默认状况下docker安装过程当中会自动建立一个docker用户组
sudo gpasswd -a ${USER} docker
注意以上命令只能用当前用户来操做,由于变量
USER
获取的是当前用户,若是要以root用户来操做,则须要指定的是具体的用户名,而非此变量
这里并非批退出系统,只要切换一下用户便可,好比先切到root用户而后再切回来就能够了
3.安装docker时报container-selinux >= 2.9
错误
因为测试环境的机器是不一样批准到来的,第一批安装很是顺序,第二批是直接放置在办公室的PC机,也很是不顺序,安装过程遇到各类各样麻烦.
上面说过,加入集群时发现docker没有安装成功,安装docker时出现了如下错误
Error: Package: docker-ce-18.03.1.ce-1.el7.centos.x86_64 (docker-ce-edge)
Requires: container-selinux >= 2.9
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
这个报错是container-selinux版本低或者是没安装的缘由
yum 安装container-selinux 通常的yum源又找不到这个包
须要安装epel源 才能yum安装container-selinux
而后在安装docker-ce就能够了。
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release #阿里云上的epel源
yum makecache
而后yum install container-selinux