-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker.py
More file actions
102 lines (83 loc) · 2.59 KB
/
docker.py
File metadata and controls
102 lines (83 loc) · 2.59 KB
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
import os
# Configure and Install Docker
def docker_config():
print('yum should be configured before docker installation .')
os.system('sudo yum config\-manager \-\-add\-repo\=https\:\/\download.docker.com\/linux\/centos\/docker\-ce\.repo')
os.system('dnf install docker-ce --nobest -y')
os.system('systemctl start docker')
os.system('systemctl status docker')
# Configure Web Server on Docker
def docker_web():
os.system('docker run -dit --name webos -p 8080:80 centos')
os.system('docker exec webos yum install httpd -y')
os.system('docker cp index.html webos:/var/www/html/')
os.system('docker exec webos /usr/sbin/httpd')
input()
# Launch Python Interpreter on Docker
def docker_py():
os.system('docker run -dit --name pyos centos')
os.system('docker exec pyos yum install python3 -y')
os.system('docker cp hello.py pyos:/')
print()
os.system('docker exec pyos python3 /hello.py')
input()
# Launch GUI APP inside Docker
def docker_gui():
os.system('docker run -it --name gui --env="DISPLAY" --net=host firefox:v1')
input()
# Docker Menu
def docker_menu():
while True:
os.system("clear")
os.system("tput setaf 1")
print("\t\t ----------------------------------")
print("\t\t | Welcome to Docker Assistant !! |")
print("\t\t ----------------------------------")
os.system("tput setaf 7")
os.system("tput setaf 2")
print("""
Press 1 : To Configure Docker
Press 2 : To Search Docker Image
Press 3 : To Pull Docker Image
Press 4 : To List Container
Press 5 : To Remove all the Container
Press 6 : To Configure Webserver on Docker
Press 7 : To Run Python Code on Docker
Press 8 : To Launch GUI program in Docker
Press 9 : To Return to Previous Menu
""")
print()
os.system("tput setaf 3")
ch = input("\t\t Enter your Choice : ")
os.system("tput setaf 7")
if int(ch) == 1:
docker_config()
elif int(ch) == 2:
os.system("tput setaf 3")
image_name = input("Enter the OS Name : ")
os.system("tput setaf 7")
os.system("docker search {0}".format(image_name))
input()
elif int(ch) == 3:
os.system("tput setaf 3")
image_name = input("Enter the OS Name : ")
os.system("tput setaf 7")
os.system("docker pull {0}".format(image_name))
input()
elif int(ch) == 4:
os.system("docker ps -a")
input()
elif int(ch) == 5:
os.system("docker rm -f $(docker ps -aq)")
input()
elif int(ch) == 6:
docker_web()
elif int(ch) == 7:
docker_py()
elif int(ch) == 8:
docker_gui()
elif int(ch) == 9:
break
else:
print("Please Select Correct Choice")
input()