1. 系统要求
centos7以上 使用cat /etc/redhat-release查看系统版本,我的Centos 7.6
centos-extra 仓库 enable,默认是打开的
2.安装docker
docer安装分为联网安装和离线安装两种安装 方式,
第一种 在有外网环境下安装docker,一般使用yum安装,我是在本地虚拟机上安装的
2.1 手动在yum源添加 docer仓库
touch /etc/yum.repos.d/docker.repo
在这个仓库文件中添加如下内容:
[docker-ce-stable] name=Docker CE Stable - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/stable enabled=1 gpgcheck=0 #我把这里设置成了0、说明我信任了这个源,不对它的rpm进行检察gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-stable-debuginfo] name=Docker CE Stable - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-stable-source] name=Docker CE Stable - Sources baseurl=https://download.docker.com/linux/centos/7/source/stable enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge] name=Docker CE Edge - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/edge enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge-debuginfo] name=Docker CE Edge - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/edge enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-edge-source] name=Docker CE Edge - Sources baseurl=https://download.docker.com/linux/centos/7/source/edge enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test] name=Docker CE Test - $basearch baseurl=https://download.docker.com/linux/centos/7/$basearch/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test-debuginfo] name=Docker CE Test - Debuginfo $basearch baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg [docker-ce-test-source] name=Docker CE Test - Sources baseurl=https://download.docker.com/linux/centos/7/source/test enabled=0 gpgcheck=1 gpgkey=https://download.docker.com/linux/centos/gpg
2.2 yum makecache 就是把服务器的包信息下载到本地电脑缓存起来
2.3 sudo yum install docker-ce 安装最新版本的docker
当然也可以查看仓库中所有的docker版本,选择特定版本安装
yum list docker-ce --showduplicates | sort -r
比如 sudo yum install docker-ce-17.12.0.ce
2.4 查看docker是否安装成功
docker version 或者 docker info
2.5 启动docker
sudo systemctl start docker
第二种 离线安装方式
下载.rmp文件,并且手动安装。下载网址:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
docker-ce-selinux-17.03.0.ce-1.el7.centos.noarch.rpm
配置镜像加速器
针对Docker客户端版本大于 1.10.0 的用户
可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器,如果daemon.json文件不存在,就创建一个
cd /etc/docker
touch daemon.json
添加如下内容
{"registry-mirrors": ["https://mrkxppsh.mirror.aliyuncs.com"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker