侧边栏壁纸
  • 累计撰写 94 篇文章
  • 累计创建 35 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

docker安装

天明
2024-03-05 / 0 评论 / 0 点赞 / 67 阅读 / 3842 字 / 正在检测是否收录...

docker安装脚本

# step 1: 安装必要的一些系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 官方:yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# VPC网络时可用:yum-config-manager --add-repo http://mirrors.cloud.aliyuncs.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装Docker-CE
yum makecache
echo "当前可用版本"
yum list docker-ce.x86_64 --showduplicates | sort -r |head -n 10
DOCKER_VERSION=24.0.6
yum -y install docker-ce-${DOCKER_VERSION} docker-ce-cli-${DOCKER_VERSION} containerd.io docker-compose-plugin
# 直接安装最新版本
# yum -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
echo "生成docker默认配置文件:/etc/docker/daemon.json"
mkdir -p /www/docker && mkdir -p /etc/docker
tee /etc/docker/daemon.json <<EOF
{
  "data-root": "/www/docker",
  "registry-mirrors" : [
    "https://registry.aliyuncs.com",
    "https://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
  ],
  "exec-opts": ["native.cgroupdriver=systemd"],
  "max-concurrent-downloads": 20,
  "max-concurrent-uploads": 10,
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "300m",
    "max-file": "21"
  },
  "storage-driver": "overlay2"
}
EOF
# Step 4: 开启Docker服务 systemctl enable docker && systemctl start docker
echo "设置docker服务开机启动"
systemctl enable docker
echo "启动docker服务"
systemctl start docker

docker使用firewall防火墙配置

vim /lib/systemd/system/docker.service 添加参数:--iptables=false
ExecStart=/usr/bin/dockerd -H fd:// --iptables=false --containerd=/run/containerd/containerd.sock
systemctl daemon-reload
systemctl restart docker
systemctl restart firewalld

常见问题(systemctl status docker)

出错提示1:Not using native diff for overlay2, this may cause degrade

修复:
echo "options overlay metacopy=off redirect_dir=off" >> /etc/modprobe.d/disable-overlay-redirect-dir.conf
systemctl stop docker
# 重新加载内核模块
modprobe -r overlay
modprobe overlay
# 启动
systemctl start docker

出错提示2:WARNING: bridge-nf-call-iptables is disabled

出错提示2:
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
修复:
echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf
echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
# 加载br_netfilter内核模块
modprobe br_netfilter
sysctl -p
0

评论区