环境准备
1:需要一定的linux基础
2:Centos 7
环境查看
#系统内核是3.10以上的
[root@localhost ~]# uname -r
3.10.0-1160.el7.x86_64
#系统版本
[root@localhost ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
安装
#1、卸载旧的版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
#2、需要的安装包
sudo yum install -y yum-utils
#3、设置镜像的仓库
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软件索引
yum makecache fast
#4、安装docker docker-ce 社区版,**-ee 是企业版
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
#5、启动docker
systemctl start docker
#6、查看docker是否启动成功
docker version
#7、hello-world
docker run hello-world
8、查看下载的hello-world镜像
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 14 months ago 13.3kB
卸载
#1、卸载依赖
sudo yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
#2、删除资源
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
# /var/lib/docker docker的默认工作路径
# /var/lib/containerd 存储镜像和数据
可能遇到的问题
Failed to start docker.service: Unit not found
遇到这个问题
首先检查使用的命令是否和上面的相同,(确保命令都执行正确)
其后有可能是因为防火墙没有关闭的原因
处理:
#检查防火墙是否开启:
firewall-cmd --state
如果是:running 状态则是开启状态,
关闭防火墙:
systemctl stop firewalld.service
禁止防火墙开机自启:
systemctl disable firewalld.service
再重新安装一遍即可。