#coding=utf-8
import os


def install_docker():
    # 关闭防火墙
    print('关闭防火墙...')
    res = os.system('''systemctl stop firewalld && systemctl disable firewalld''')
    if res == 1: raise RuntimeError('关闭防火墙失败')

    # step1 = os.system("wget -qO- https://get.docker.com/ | sh")
    # assert step1 == 0, "docker 安装失败"
    os.system("sudo mkdir -p /etc/docker")
    step2 = os.system("""
        sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors":["https://m6wlkecl.mirror.aliyuncs.com"],
    "insecure-registries": ["http://47.110.145.204:8084","http://183.134.73.2:8084"],
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "50m",
        "max-file": "3"
    }
}
EOF
        """)
    assert step2 == 0, "docker 镜像地址更新失败"
    os.system("sudo systemctl daemon-reload")
    os.system("sudo systemctl restart docker")
    print("docker安装成功")


if __name__ == "__main__":
    install_docker()
