#!/usr/bin/env python3 import os import docker import sys docker.cmd('container prune -f') all = docker.cmd('image ls') for each in all: data = list(filter(lambda e: e != '', each.split(' '))) name = data[0] id = data[2] print('删除' + name) docker.cmd('image rm ' + id)
#!/usr/bin/env python3 import os, docker, json all = docker.cmd('ps -a') runs = [] rms = [] for each in all: data = each.split(' ') id = data[0] name = data[len(data) - 1] jsobj = json.loads(docker.cmd('inspect ' + id, False))[0] config = jsobj['Config'] network = jsobj['NetworkSettings'] ports = network['Ports'] mounts = jsobj['Mounts'] run = ['docker run -dti'] rm = ['\n# ' + name + '\n', 'docker rm -f'] run.append('-h ' + name) run.append('--name ' + name) rm.append(id) for key in ports: cfg = ports[key] if cfg: cfg = cfg[0] run.append('-p ' + cfg['HostIp'] + ':' + str(cfg['HostPort']) +
#!/usr/bin/env python3 import os, docker, sys all = docker.cmd('ps -a') script = sys.argv[1] for each in all: data = each.split(' ') id = data[0] print('执行' + id) docker.cmd('cp ' + script + ' ' + id + ':/root/tmp_script') docker.cmd('exec -ti ' + id + ' /root/tmp_script') docker.cmd('exec -ti ' + id + ' rm /root/tmp_script')
#!/usr/bin/env python3 import os, docker, sys all = docker.cmd('ps -a') script = sys.argv[1] for each in all: data = each.split(' ') id = data[0] print('删除' + id) docker.cmd('rm -f ' + script + ' ' + id)
#!/usr/bin/env python3 import os import docker import json all = docker.cmd('service ls') runs = [] rms = [] for each in all: data = list(filter(lambda e: e != '', each.split(' '))) id = data[0] repl = data[3].split('/')[1] image = data[4] jsobj = json.loads(docker.cmd('service inspect ' + id, False))[0] spec = jsobj['Spec']['TaskTemplate'] network = spec['Networks'][0] endpoint = jsobj['Endpoint'] run = ['docker service create '] rm = ['docker service rm'] rm.append(id) for each in spec['Placement']['Constraints']: run.append('--constraint "' + each + '"') if 'Ports' in endpoint: for each in endpoint['Ports']: