-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
43 lines (31 loc) · 1.33 KB
/
run.py
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
import subprocess
import sys
import time
timeOut = 10
dockers = ["docker1", "docker2", "docker3"]
def shuffle(my_list):
first_element = my_list.pop(0)
my_list.append(first_element)
for i in range(1, 100, 1):
shuffle(dockers)
print("\ndocker up ====>", dockers,"<====\n")
for i in range(3):
try:
# docker run --rm -d --name docker2 --network my_docker_network --ip 192.168.0.2 docker2
command = "docker run --rm -d --name " + dockers[i] + " --network my_docker_network --ip 192.168.0." + str(i + 2) + " " + dockers[i]
print("==> 192.168.0." + str(i + 2) + " <==")
output = subprocess.check_output(command, shell=True, text=True)
except:
print("failed to run docker : ", dockers[i])
print("\nsuccessfully run dockers....")
time.sleep(timeOut)
print("\n")
for i in range(3):
try:
command = "docker ps --filter ancestor=" + dockers[i] + " --format '{{.ID}}'"
print(" stop ==> " + dockers[i])
container_id = subprocess.check_output(command, shell=True, text=True)
command = "docker stop " + container_id
container_id = subprocess.check_output(command, shell=True, text=True)
except:
print("failed to stop docker : ", dockers[i])