脚本使用方式:
将脚本拷贝到服务器中,并且此脚本目录下有docker的tar包,不需要修改脚本文件,直接执行即可!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/python
# -*- coding: utf-8 -*-
import os


def install():
##################################
# version = 'docker-19.03.9.tgz'
version = os.popen('ls . | grep ^docker | grep tgz$').read().replace('\n', '')
##################################

os.system('tar xf ' + version + ' -C /usr/src')
os.system('cp /usr/src/docker/* /usr/bin/')

file = os.path.exists(dockerfile)
if file == 'False':
os.system('touch ' + dockerfile)
wfile()
else:
wfile()
os.system('chmod +x ' + dockerfile)
os.system('systemctl daemon-reload && '
'systemctl start docker && '
'systemctl enable docker.service && '
'setenforce 0 >& /dev/null')

print('Docker Version as follows:')
os.system('docker -v')


def wfile():
file = open(dockerfile, 'w')
file.write('[Unit] \n'
'Description=Docker Application Container Engine \n'
'Documentation=https://docs.docker.com \n'
'After=network-online.target firewalld.service \n'
'Wants=network-online.target \n'
'[Service] \n'
'Type=notify \n'
'ExecStart=/usr/bin/dockerd \n'
'ExecReload=/bin/kill -s HUP $MAINPID \n'
'LimitNOFILE=infinity \n'
'LimitNPROC=infinity \n'
'LimitCORE=infinity \n'
'TimeoutStartSec=0 \n'
'Delegate=yes \n'
'KillMode=process \n'
'Restart=on-failure \n'
'StartLimitBurst=3 \n'
'StartLimitInterval=60s \n'
'[Install] \n'
'WantedBy=multi-user.target')
file.close()


if __name__ == '__main__':
dockerfile = '/etc/systemd/system/docker.service'
install()