:::info 视频演示 https://www.bilibili.com/video/BV1B3411q7Bs/ :::
Centos 7.8
在线
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
curl -sSL https://get.daocloud.io/docker | sh
systemctl enable docker
systemctl start docker
# 国内下载
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.2.3/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
离线
下载资源
sudo yum install -y --downloadonly --downloaddir=$PWD/devel yum-utils device-mapper-persistent-data lvm2
sudo yum install -y devel/*.rpm
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y --downloadonly --downloaddir=$PWD/docker docker-ce
curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` > ./docker-compose
安装
sudo yum install -y devel/*.rpm
sudo yum install -y docker/*.rpm
systemctl enable docker
systemctl start docker
chmod a+x ./docker-compose
cp ./docker-compose /usr/bin/
系统调优
echo off
# 关闭selinux
#setenforce 0
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# 关闭防火墙
systemctl stop firewalld.service && systemctl disable firewalld.service
# 修改时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 系统语言
sudo echo 'LANG="en_US.UTF-8"' >> /etc/profile;source /etc/profile
# 关闭swap
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# 性能调优
cat >> /etc/sysctl.conf<<EOF
vm.swappiness = 0
kernel.sysrq = 1
net.ipv4.neigh.default.gc_stale_time = 120
# see details in https://help.aliyun.com/knowledge_detail/39428.html
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
# see details in https://help.aliyun.com/knowledge_detail/41334.html
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv4.ip_forward=1
EOF
sysctl -p
Docker容器实例中解析DNS的顺序
- 查找Docker daemon内置的DNS服务器127.0.0.11
- 查找docker run创建容器实例时通过—dns参数设置的DNS服务器
- 查找Docker daemon通过—dns参数,或/etc/docker/daemon.json文件设置的DNS服务器
- 查找Docker宿主机上/etc/resolv.conf文件中配置的DNS服务器
- 查找Google的DNS服务器,如8.8.8.8和8.8.4.4,2001:4860:4860::8888和2001:4860:4860::8844
docker 加速
# /etc/docker/daemon.json
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]