Docker 一键部署

#!/bin/bash

#环境配置
systemctl stop firewalld && systemctl disable firewalld
setenforce 0

#安装依赖包
yum -y install yum-utils device-mapper-persistemt-data lvm2

#设置阿里云镜像源
cd /etc/yum.repos.d/
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#安装 docker-ce 社区版(企业版叫 docker-ee,收费)
yum -y install docker-ce

#配置阿里云镜像加速(尽量使用自己的)
#地址 https://help.aliyun.com/document_detail/60750.html
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://4iv7219l.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload

#网络优化
cat >> /etc/sysctl.conf <<EOF
net.ipv4.ip_forward=1
EOF

sysctl -p
systemctl restart network
systemctl enable docker && systemctl restart docker
原文地址:https://www.cnblogs.com/shenyuanhaojie/p/15634719.html