Linux一键安装Docker-CE及配置优化

Linux一键安装Docker-CE及配置优化

先森的小酒馆 495 2022-10-24

Linux一键安装Docker-CE及配置优化

Linux/Centos7.x安装Docker-CE及优化配置,使用国内镜像加速,安装更快

以Centos7为例,另一篇安装Docker-CE教程链接:Centos6.x和Centos7.x安装Docker

Centos7其他命令

CentOS关闭selinux

sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

关闭防火墙

systemctl stop firewalld.service && systemctl disable firewalld.service

官方脚本安装(支持全系统)

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

腾讯云脚本安装(CentOS/RHEL支持)

https://mirrors.tencent.com/help/docker-ce.html

# CentOS/RHEL
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
# 把软件仓库地址替换为:
sudo sed -i 's+download.docker.com+mirrors.cloud.tencent.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# 安装
sudo yum makecache fast
sudo yum install docker-ce
# 设置开机启动
sudo systemctl enable docker

Docker相关命令

    # (start, stop, restart, try-restart, reload, force-reload, status)
    systemctl start docker

Docker优化配置设置

通过修改daemon.json来改过Docker配置,daemon.json默认位于/etc/docker/daemon.json,如果没有可手动创建

    sudo tee /etc/docker/daemon.json <<-'EOF'
    {
        "max-concurrent-downloads": 10,
        "max-concurrent-uploads": 5,
        "insecure-registries": ["0.0.0.0/0"],
        "registry-mirrors": ["https://mirror.ccs.tencentyun.com","http://f1361db2.m.daocloud.io"],
        "storage-driver": "overlay2",
        "storage-opts": ["overlay2.override_kernel_check=true"],
        "log-driver": "json-file",
        "log-opts": {
            "max-size": "100m",
            "max-file": "3"
            }
    }
    EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker

max-concurrent-downloads 下载线程数
max-concurrent-uploads 上传线程数
registry-mirrors 国内docker镜像仓库地址