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

2018-09-29
1412
0
0

温馨提示:本文最后更新于 2024-06-08,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

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

以Centos7为例,另一篇安装Docker-CE教程链接:https://4xx.me/archives/52.html

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 --version 24.0

腾讯云脚本安装(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",
    "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镜像仓库地址

为Docker设置代理

vim /lib/systemd/system/docker.service

# 在[Service]下添加
Environment=HTTP_PROXY=http://proxyAddress:port
Environment=HTTPS_PROXY=http://proxyAddress:port
Environment=NO_PROXY=localhost,127.0.0.1

配置完成重载配置并重启docker


评论

Polar.
最重要的,是拥有跟随内心与直觉的勇气

文章目录