-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.py
118 lines (101 loc) · 4.18 KB
/
docker.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import platform
def dockerMenu():
if platform.system() == 'Windows':
print("Current OS is Windows. This Code Block is compatible only with Red Hat Enterprise Linux.")
input("Press Enter to return to menu...")
return
print("\t\t\tWhat do you want to do? \n")
print("\t\t1 : Install docker")
print("\t\t2 : Start docker service")
print("\t\t3 : Stop docker service")
print("\t\t4 : View docker info")
print("\t\t5 : View active containers")
print("\t\t6 : View all containers")
print("\t\t7 : View downloaded images")
print("\t\t8 : Pull an image")
print("\t\t9 : Launch a container")
print("\t\t10 : Stop a container")
print("\t\t11 : Start a container")
print("\t\t12 : Remove an image")
print("\t\t13 : Remove a container")
print("\t\t0 : Exit")
print()
while(True):
option=int(input("\n\tEnter your choice : "))
if (option==1):
if not os.system("{} rpm -q docker-ce"):
print("\tDocker is already installed. Exiting installation...")
else:
print("\tInstalling Docker...")
file=open("/etc/yum.repos.d/docker-ce_install.repo","a")
dockrepo = "[docker]\nbaseurl=https://download.docker.com/linux/centos/7/x86_64/stable/\ngpgcheck=0\n"
file.write(dockrepo)
file.close()
os.system("yum install docker-ce --nobest")
elif (option==2):
os.system("systemctl start docker")
elif (option==3):
os.system("systemctl stop docker")
elif (option==4):
os.system("docker info")
elif (option==5):
os.system("docker ps")
elif (option==6):
os.system("docker ps -a")
elif (option==7):
os.system("docker images")
elif (option==8):
image=input("\tEnter image name: ")
version=input("\tEnter image version (optional): ")
if image:
if version != "" :
os.system("docker pull {}:{}".format(image,version))
else :
os.system("docker pull {}".format(image))
else:
print("\n\tNo image name entered!")
elif (option==9):
img = input("\tEnter image name: ")
ver = input("\tEnter image version (optional): ")
name = input("\tEnter container name: ")
if image:
if version != "" :
os.system("docker run -it --name {} {}:{}".format(name,image,version))
else :
os.system("docker run -it --name {} {}".format(name,image))
else:
print("\n\tNo image name entered!")
elif (option==10):
name_id = input("\tEnter container name or id: ")
if name_id :
os.system("docker stop {}".format(name_id))
else :
print("\tPlease enter a container name/ID!")
elif (option==11):
name_id = input("\tEnter container name or ID: ")
if name_id :
os.system("docker start {}".format(name_id))
else :
print("\tPlease enter a container name/ID!")
elif(option==12):
img = input("\tEnter image name: ")
ver = input("\tEnter image version (optional): ")
if img:
if ver != "" :
os.system("docker rmi {}:{} --force".format(img,ver))
else:
os.system("docker rmi {} --force".format(img))
else:
print("\tPlease enter an image name!")
elif (option==13):
name_id = input("\tEnter container name or ID: ")
if name_id :
os.system("docker rm {}".format(name_id))
else :
print("\tPlease enter a container name/ID!")
elif (option==0):
break
else:
print("\tInvalid choice!\n")
return