Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Termidock πŸ–₯️

A browser based terminal emulator built as part of a hiring task. Users can launch an isolated Ubuntu Docker container directly from the browser, type commands, and see live output all in real time via WebSockets.


Task Overview

Build a Browser-Based Terminal App where the user opens the browser and clicks a "Launch Lab" button. A Docker container is created for that session. The user can type commands in the browser terminal, which run inside the container β€” just like Killercoda.


Tech Stack

Layer Technology
Frontend HTML, CSS, JavaScript
Terminal UI Xterm.js
Backend Python, Django
Real-time Django Channels (WebSocket)
Container Docker (Ubuntu image)
Docker Integration Docker SDK for Python
Server ASGI via Daphne / Uvicorn

Project Structure

Terminal-project/
β”œβ”€β”€ README.md
└── termidock/
    β”œβ”€β”€ manage.py                  # Django management script
    β”œβ”€β”€ requirements.txt           # Python dependencies
    β”œβ”€β”€ static/                    # Static files (CSS, JS, assets)
    β”œβ”€β”€ templates/
    β”‚   └── index.html             # Main frontend β€” Launch Lab UI + Xterm.js terminal
    β”œβ”€β”€ lab/                       # Core Django app β€” terminal & Docker logic
    β”‚   β”œβ”€β”€ __init__.py
    β”‚   β”œβ”€β”€ consumers.py           # WebSocket consumer β€” bridges browser ↔ Docker container
    β”‚   β”œβ”€β”€ routing.py             # WebSocket URL routing
    β”‚   β”œβ”€β”€ urls.py                # HTTP URL patterns for the lab app
    β”‚   └── views.py               # HTTP views β€” serves the frontend page
    └── terminal_lab/              # Django project configuration
        β”œβ”€β”€ __init__.py
        β”œβ”€β”€ asgi.py                # ASGI entry point β€” routes HTTP + WebSocket connections
        β”œβ”€β”€ settings.py            # Project settings (Channels, installed apps, etc.)
        └── urls.py                # Root URL configuration

How It Works

Browser (Xterm.js)
      |
      |  WebSocket
      ↓
Django Channels (consumers.py)
      |
      |  Docker SDK for Python
      ↓
Ubuntu Docker Container
  1. The user opens the app and sees the Ubuntu Labs page (index.html).
  2. Clicking Launch Lab sends a request to the backend, which uses the Docker SDK to spin up a new Ubuntu container.
  3. The browser opens a WebSocket connection handled by lab/consumers.py.
  4. The consumer attaches to the container's shell (exec session), relaying input/output in real time.
  5. Output from the container streams back to Xterm.js in the browser.
  6. When the user clicks End Lab (or closes the tab), the consumer stops and removes the container automatically.

Getting Started

Prerequisites

  • Python 3.12+
  • Docker (running locally)
  • pip

Installation

# Pull the Ubuntu Docker image (first time only)
docker pull ubuntu

# Clone the repository
git clone https://github.com/HashimN225/Terminal-Project.git
cd Terminal-Project/termidock

# Create and activate virtual environment
# Mac and Linux
python3 -m venv myvenv
source myvenv/bin/activate

# Windows
python -m venv myvenv
myvenv\Scripts\activate

# Install Python dependencies
pip install -r requirements.txt

# Run the development server
daphne -b 0.0.0.0 -p 8000 terminal_lab.asgi:application

Then open your browser and go to http://localhost:8000.

Usage

  1. After opening, http://localhost:8000 in your browser.
  2. Click Launch Lab β€” a Docker container starts and the terminal appears.
  3. Type any Linux command (e.g., ls, pwd, echo hello) and hit Enter.
  4. The command runs inside the container and output appears instantly.
  5. Click End Lab to stop and remove the container.
  6. (Optional) Click Reset Lab to restart with a fresh container.

Requirements

See requirements.txt for the full list of dependencies. Key packages include:

  • django β€” Web framework
  • channels β€” WebSocket support via ASGI
  • docker β€” Docker SDK for Python
  • daphne β€” ASGI server

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages