WEB APPLICATION FOR DOCKER CONTAINER

Bolisetti Guna Sekhar
1 min readJun 25, 2021

7.1

Here i integrate backend (python file) with frontend (html) this webapplication allows us to run docker commands from web application we can see the output/result in the same webapplication

prerequisite:httpd server program,docker

file to be there in /var/www/html this is default path

It is recommended to place client side programming files in this path

main html file and javascript file

code:main.html

<!DOCTYPE html>
<html>
<head>
<title>Docker Webpage</title>
<script src=’main.js’></script>
<body style=”background-color:skyblue”>
<center> <img src=”docker.jpg”> </center>
<div>
<h2 align=”center” >
<p>
[root@localhost ~]#
<input id=”input” required=”True” type=”text” placeholder=”Enter your required command” style=”width: 50%;margin-bottom:10px;height=20%” />
<button class=”button” onclick=”lw();”>click here</button>
</p>
</h2>
</div>
<pre>
<h2 style=”color:rgb(0, 0, 0)”>
<div id=”d1" align=”center” ></div>
</h2>
</pre>
</body>
</html>

Javascriptfile:

function lw() {
var i=document.getElementById(“input”).value
var xhr = new XMLHttpRequest()

xhr.open(“GET”,”http://ipaddress of you webserver/cgi-bin/linux.py?cmd="+i,true);
xhr.send();
xhr.onload = function(){
var output = xhr.responseText;
document.getElementById(“d1”).innerHTML=output;
}
}

Backend application:docker.py

#!/usr/bin/python3
print(“content-type:text/plain”)
print()

import subprocess as p
import cgi

url=cgi.FieldStorage()
command=url.getvalue(“cmd”)
output=p.getoutput(“sudo “+command)
print(output)

--

--