1.安装Docker
我是虚拟机装的Centos7,linux 3.10 内核,docker官方说至少3.8以上,建议3.10以上(ubuntu下要linux内核3.8以上, RHEL/Centos 的内核修补过, centos6.5的版本就可以——这个可以试试)
shell > uname -a
#Linux localhost.qgc 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14 21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
2.Yum包更新,((可选)把yum包更新到最新(生产环境慎重!yum update会对软件包和内核升级,此处只是为了排除系统环境的影响,来自笔者的备注—2019年10月30日)
shell > yum update
3.安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
shell > yum install -y yum-utils device-mapper-persistent-data lvm2
#Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: centos.ustc.edu.cn
4.设置YUM源,提高下载速度
shell > 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
repo saved to /etc/yum.repos.d/docker-ce.repo
5.可以查看所有仓库中所有docker版本,并选择特定版本安装
shell > yum list docker-ce --showduplicates | sort -r
##* extras: mirrors.aliyun.com
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
(建议选择低一个版本的docker)
6.安装Docker,命令:yum install docker-ce-版本号,我选的是17.12.1.ce,如下
shell > yum install docker-ce-17.12.1.ce
#正在解决依赖关系
--> 正在检查事务
---> 软件包 docker-ce.x86_64.0.17.12.1.ce-1.el7.centos 将被 安装
--> 正在处理依赖关系 container-selinux >= 2.9,它被软件包 docker-ce-17.12.1.ce-1.el7.centos.x86_64 需要
7.启动Docker,命令:systemctl start docker,然后加入开机启动,如下
shell > systemctl start docker
shell > systemctl enable docker
#Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
8.验证安装是否成功(有client和service两部分表示docker安装启动都成功了)
shell > docker version
#Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 7390fc6
1.1启动docker
启动后:下载官方的 CentOS 镜像到本地
shell > docker pull centos
#Pulling repository centos
192178b11d36: Download complete
70441cac1ed5: Download complete
ae0c2d0bdc10: Download complete
511136ea3c5a: Download complete
5b12ef8fd570: Download complete
1.2确认 CentOS 镜像已经被获取
shell > docker images centos
#REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos5 192178b11d36 2 weeks ago 466.9 MB
centos centos6 70441cac1ed5 2 weeks ago 215.8 MB
1.3运行一个 Docker 容器
shell > docker run -i -t centos /bin/bash
[root@dbf66395436d /]#
1.4我们可以看到 CentOS 容器已经被启动,并且我们看到了 bash 提示符。在 docker 命令中我们使用了 “-i 捕获标准输入输出”和 “-t 分配一个终端或控制台”选项。
若要断开与容器的连接,则输入 exit。
[root@dbf66395436d /] > cat /etc/redhat-release
#CentOS Linux release 7.0.1406 (Core)
[root@dbf66395436d /] > exit