## Docker的安装与卸载
Docker 有两个版本:
- 社区版(Community Edition,缩写为 CE)
- 企业版(Enterprise Edition,缩写为 EE)
> 在这里我安装的是社区版。
### 检查环境
```apache
# 系统内核需要 3.10 以上
uname -r
3.10.0-1062....
# 查看系统版本
cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
```
![image-20220307160933306](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220307160933306.png)
### 安装 docker
```awk
# 卸载旧版本
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 安装依赖包
$ sudo yum install -y yum-utils
# 设置镜像仓库(不推荐使用官方仓库,速度很慢)
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
# 设置镜像仓库(推荐使用阿里云仓库)
$ sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 更新yum软件包索引
$ sudo yum makecache fast
# 安装社区版docker
$ sudo yum install docker-ce docker-ce-cli containerd.io
```
![image-20220307161100038](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220307161100038.png)
![image-20220307161242743](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220307161242743.png)
### 启动测试
```powershell
# 服务方式启动
$ sudo systemctl start docker
# 查看版本
$ sudo docker version
# 测试运行容器
$ sudo docker run hello-world
# 查看下载的镜像
$ sudo docker images
```
![image-20220307161825140](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220307161825140.png)
出现如下信息,即表示已经安装成功。
![image-20220307194035110](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220307194035110.png)
### 使用阿里云加速器
![image-20220307170714276](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220307170714276.png)
![image-20220307170810842](https://mybolg-typora.oss-cn-beijing.aliyuncs.com/image-20220307170810842.png)
### 卸载 docker
```powershell
# 停止服务
$ sudo systemctl start docker
# 卸载相关依赖
$ sudo yum remove docker-ce docker-ce-cli containerd.io
# 清空工作路径
$ sudo rm -rf /var/lib/docker
```
Docker的安装与卸载