1. 实验环境:
镜像:centos7
网络:能通外网(NAT模式)
软件:VMware Workstation Pro + xshell7
2. 创建脚本文件 docker_script.sh
vi docker_script.sh

3. 将以下内容复制到脚本中
#!/bin/bash
systemctl stop firewalld ; #//关闭防火墙
systemctl disable firewalld ; #//禁用防火墙
setenforce 0 ; #//临时关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config ; #//替换文件内容,关闭selinux
read -p "输入你的网卡配置文件名字:" file ; #//为网卡配置文件添加一条DNS服务,输入ens33(根据自己主机网卡名输入)
echo "DNS2=114.114.114.114" >> /etc/sysconfig/network-scripts/$file ;
systemctl restart network ; #//重启网卡
yum -y update ; #//更新yum仓库
yum clean all ; #//清除原有的缓存
yum makecache ; #//生成新的缓存
yum install ntpdate ; #//下载时间服务器
ntpdate ntp1.aliyun.com ; #//使用阿里云时间服务器
yum remove docker docker-common docker-selinux docker-engine ; #//卸载旧版本文件
yum install -y yum-utils device-mapper-persistent-data lvm2 ; #//安装必须的软件包
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ; #//设置yum源
echo "{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}" > /etc/docker/daemon.json ; #//配置镜像加速器
yum install -y docker-ce ; #//安装docker 最新版
systemctl start docker ; #//启动 docker
systemctl enable docker ; #//设置 docker开机自启动
docker version ; #//显示当前 docker版本

4. 启动脚本
sh docker_script.sh

5. 输入y安装

6. 安装成功


本文介绍了在CentOS7环境下,使用NAT模式并通过VMwareWorkstationPro运行虚拟机,详细步骤包括关闭防火墙、禁用SELinux、配置DNS、更新仓库、安装Docker最新版并设置镜像加速。
&spm=1001.2101.3001.5002&articleId=135161708&d=1&t=3&u=c35f4aea25e843dc998a1f5d37302471)
1622

被折叠的 条评论
为什么被折叠?



