Javascript Integration with Docker.

Sachin Joshi
4 min readJun 25, 2021

In this Blog I have created a Web Application for Docker (one of the great Containerization Tool which provides the user Platform as a Service (PaaS))

This app will help the user to run all the docker commands like:

👉docker images
👉docker ps
👉docker run
👉docker rm -f
👉docker exec

Before we start further we need a sever side code which will interact with the web server and run the python code on backend for that we need to understand what is CGI programming.

In computing, Common Gateway Interface (CGI) is an interface that enables web servers to execute an external program(python program), typically to process user requests. Such programs are often written in a scripting language and are commonly referred to as CGI scripts, but they may include compiled programs.

When weare CGI, we don’t need to store HTML pages on a server, but can be dynamically created as and when a user makes a website query.

httpd is the Apache HyperText Transfer Protocol (HTTP) server program. It is designed to be run as a standalone daemon process. When used like this it will create a pool of child processes or threads to handle requests.

Before running the server we need to install it in the OS(I am using RHEL 8)

# yum install httpd

Turn on the HTTP server

# systemctl start httpd

Your server is now live.

Now A CGI-bin is a folder used to house scripts that will interact with a Web browser to provide functionality for a Web page or website.

This is the default path generated of cgi-bin after installation of httpd. In this folder I have created a python folder docker.py and made executable , That’s the reason it showing in green colour font.

chmod +x on a file (your script) only means, that you’ll make it executable

Contents of docker.py

#!/usr/bin/python3 
import cgi
import subprocess
print("content-type: text/html")
print()
f = cgi.FieldStorage()
cmd = f.getvalue("x")
output = subprocess.getoutput("sudo\t " + cmd)
print(output)

/var/www/html is just the default root folder of the apache web server. You can change that to be whatever folder you want by editing your apache.conf file (usually located in /etc/apache/conf) and changing the DocumentRoot attribute (see http://httpd.apache.org/docs/current/mod/core.html#documentroot for info on that)

/var/www/html being the folder you want to install your website on

Contents of Test.html

Now turn off your system firewall (Terminal commands)

Now restart your server (Terminal commands)

Check your IP address:

This IP address will be used in test.html file to GET request from docker.py

Put this IP address in the search bar of your browser

IP address followed by your html File name

To allow access to webserver (termainal)

INSIDE /etc/sudoers add this line to allow access to webserver(vim editor)

After All this you are good to go and run docker commands on your Website

FINAL OUTPUT:

Ip address is matching which means Linux OS Terminal is live on Browser

Now let us run Docker Commands

You can find the Source Code here:-

You can Connect me here:-

— — — — — — — Thank You For Reading, Keep Sharing❤ — — — — — — — —

--

--