一、检查版本和内核是否合格
Docker支持64位版本的CentOS 7和CentOS 8及更高版本,它要求Linux内核版本不低于3.10。
- 检查版本
cat /etc/redhat-release
- 检查内核
uname -r
二、Docker的安装
1、自动安装
Docker官方和国内daocloud都提供了一键安装的脚本,使得Docker的安装更加便捷。下面两个二选一执行
- 官方的一键安装方式:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
- 国内 daocloud一键安装命令:
curl -sSL https://get.daocloud.io/docker | sh
- 如果都失败看手动吧
2.手动安装
- 卸载旧docker(有的换执行)
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
这个就是啥都没得
2. 安装docker的yum库
yum install -y yum-utils
2.1 如果执行报Could not retrieve mirrorlist啥啥错误,看这个文章,最后面修改网络yum源那里,跟着换一下源就行。
- 配置docker的yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4.安装docker
yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
4.1 查看是是否安装成功
docker -v
3.启动停止docker
1.启动
systemctl start docker
2.验证是否成功
docker images
3.停止docker
systemctl stop docker
注意:停止后,可能会报下面这个警告,这是因为存在一个 Docker 的 socket 单元(docker.socket),它可以在需要时自动启动 docker.service。即使停止了 docker.service,只要 docker.socket 仍然激活并监听相应的端口或路径,任何新的请求都会重新激活 docker.service。
systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
想要完全停止,就把那docker.socket停止并禁用,这样就可以把docker彻底停了:
# 停止docker.socket
systemctl stop docker.socket
# 禁用docker.socket
systemctl disable docker.socket
# 停止docker
systemctl stop docker
这样就彻底停了,不会自动启动
4. 重启
systemctl restart docker
5…设置开机自启动(可选)
systemctl enable docker
4.配置阿里镜像加速(可选)
# 创建文件夹
mkdir -p /etc/docker
# 创建配置文件写入镜像加速地址,文件默认不存在,得你自己建
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://nzcfdu4v.mirror.aliyuncs.com"]
}
EOF
# 加载配置文件
sudo systemctl daemon-reload
# 重启docker
sudo systemctl restart docker