【Docker学习系列】Docker学习1-docker安装

从本篇开始,凯哥将和大家一起学学docker。本篇是docker学习系列第一篇:安装docker。 docker安装前提条件:目前,centos发行版中的内核支持Docker.Docker运行在Centos7
64位上,要求系统为64位、linux系统内核版本为3.8以上的。凯哥所使用的的是Centos7.x
先关闭fentos的 防火墙:
查看防火墙运行情况:
systemctl status firewalld.service
关闭:
systemctl stop firewalld.service
永久关闭
systemctl disable firewalld.service
查看自己内核命令:
uname命令用于打印当前系统相关信息(内核版本号、硬件架构、主机名称和操作系统类型等)

使用cat命令:cat/etc/redhat-release
使用cat和 uname都行。

docker三要素:镜像(image)、容器(container)、仓库(repository).
centos7安装docker
地址:https://docs.docker.com/engine/install/centos/
安装步骤:
1:确定自己当前使用的系统版本号:
系统必须是centos7及以上版本cat/etc/redhat-release。如上图
2:卸载旧版本(如果之前没有安装过,此步骤可以忽略)
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

3:yum安装gcc相关
3.1:需要确保centos系统可以连接外网
3.2:yum -y install gcc
3.2:yum -y installgcc-c++
4:安装需要的软件包
我们采用从仓库安装的方法。
先安装仓库:
yum install -y yum-utils
5:设置stable镜像仓库

不能直接执行官网的设置镜像仓库命令。因为docker.com是国外的。会很慢。可能会经常出现以下问题:

所以,我们设置国内的镜像仓库。这里设置国内阿里云的。命令为:
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
6:更新yum软件包索引
yum makecache fast
7:安装dockerengine
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
会罗列出需要安装的

输入y.就开始正常安装了。遇到需要输入的地方。就输入y

当出现如下,说明安装完成了:

8:启动docker
systemctl start docker
命令输入后,没有报错。就是好消息。我们可以使用ps查看下

或者查看docker版本号:

9:测试:helloword
命令:docker run hello-world

我们再来结合docker运行图看看,刚才执行hello-word镜像。本地没有,就去远程仓库pull了。

我们在来看看复杂的运行图:

10:卸载
systemctl stop docker
yum remove docker-ce docker-ce-clie containerd.io
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
设置开机启动
systemctl enable
docker.service
关闭开机启动
systemctl disable
docker.service