Skip to content

Commit c755942

Browse files
authored
Create Python-cgi for launching the docker
This python-cgi code run a docker container automatically you just give the o.s name and docker image
1 parent 63f728d commit c755942

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/python3
2+
import subprocess
3+
import cgi
4+
5+
print("content-type: text/plain")
6+
print()
7+
8+
form = cgi.FieldStorage()
9+
10+
cname = form.getvalue("d1")
11+
cimage = form.getvalue("d2")
12+
13+
cmd = "sudo docker run -dit --name {0} {1}".format(cname,cimage)
14+
output = subprocess.getstatusoutput(cmd)
15+
status = output[0]
16+
out = output[1]
17+
18+
if status == 0:
19+
print("Container {0} launched successfully".format(cname))
20+
else:
21+
print("Error launching Container: {0}".format(cname))

0 commit comments

Comments
 (0)