#下载阿里云库源 基础仓库
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#下载阿里云库源 epel仓库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#下载docker-ce.repo文件
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#清空本地缓存
yum clean all
#生成新的缓存
yum makecache
#安装一些基础工具(centos最小安装)
yum install -y bash-completion vim lrzsz wget expect net-tools nc nmap tree dos2unix htop iftop iotop unzip telnet sl psmisc nethogs glances bc ntodate openldap-devel
#防火墙停用
systemctl stop firewalld
#关闭防火墙自启动服务
systemctl disable firewalld
二、配置网卡
#开启linux内核的流量转发
cat <<EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward=1
EOF
#重新加载网桥过滤模块
modprobe br_netfilter
#加载修改内核的参数,配置文件
sysctl -p /etc/sysctl.d/docker.conf
三、安装docker-ce社区版
#查看源中可用版本
yum list docker-ce --showduplicates | sort -r
#yum安装docker版本
yum install docker-ce-20.10.6 -y
#卸载命令docker
yun remove -y docker-XXX(版本号)
四、配置镜像加速器
#创建docker文件夹
mkdir -p /etc/docker
#创建文件
touch /etc/docker/daemon.json
#编辑文件
vi /etc/docker/daemon.json
添加阿里云镜像下载地址
{
"registry-mirrors": ["https://qqmbqch0.mirror.aliyuncs.com",
"https://hub-mirror.c.163.com/",
"https://reg-mirror.qiniu.com"]
}
查看配置镜像文件
cat /etc/docker/daemon.json
#激活docker配置文件
systemctl daemon-reload
启动docker
sudo systemctl start docker
#测试
docker run hello-world
#通过运行 hello-world 映像来验证是否正确安装了 Docker Engine-Community
查看运行容器
docker ps -a
#设置docker开机启动服务
systemctl enable docker
#重启docker服务
systemctl restart docker
#查看docker是否启动成功
ps -ef|grep docker
docker version