| --- |
| title: Ubuntu Desktop |
| emoji: π§ |
| colorFrom: indigo |
| colorTo: blue |
| sdk: docker |
| pinned: false |
| --- |
| |
| # π§ Ubuntu Desktop on Hugging Face Spaces |
|
|
| A browser-accessible **Ubuntu 24.04 XFCE Desktop** running on a free Hugging Face |
| Docker Space β inspired by Android Termux + PRoot-Distro workflows, adapted for |
| cloud deployment with zero manual setup. |
|
|
| --- |
|
|
| ## β¨ What You Get |
|
|
| | Feature | Detail | |
| |---|---| |
| | **Desktop** | Ubuntu 24.04 + XFCE4, accessible from any browser | |
| | **VNC** | TigerVNC (Xvnc) at 1280Γ720, 16-bit colour, 24 FPS | |
| | **Browser Access** | noVNC via WebSocket β no VNC client needed | |
| | **Persistent Storage** | All data stored in `/data` β survives Space restarts | |
| | **Dashboard** | Flask app with live CPU / RAM / disk stats + log viewer | |
| | **Browser** | Firefox ESR pre-installed | |
| | **Free CPU Tier** | Optimised for low RAM + CPU (β 400 MB idle) | |
|
|
| --- |
|
|
| ## π Deployment to Hugging Face Spaces |
|
|
| ### Prerequisites |
|
|
| - A [Hugging Face](https://huggingface.co) account |
| - Git installed locally (or use the HF web UI) |
|
|
| ### Step 1 β Create a new Space |
|
|
| 1. Go to **huggingface.co/new-space** |
| 2. Choose **Docker** as the Space SDK |
| 3. Set hardware to **CPU Basic** (free tier) |
| 4. Enable **Persistent Storage** in the Space settings (required for `/data`) |
|
|
| ### Step 2 β Upload the files |
|
|
| Either use the HF web editor to paste each file, or clone the Space repo and push: |
|
|
| ```bash |
| git clone https://huggingface.co/spaces/<YOUR_USERNAME>/<YOUR_SPACE_NAME> |
| cd <YOUR_SPACE_NAME> |
| |
| # Copy all project files here |
| cp -r /path/to/hf-ubuntu-space/* . |
| |
| git add . |
| git commit -m "Initial Ubuntu Desktop Space" |
| git push |
| ``` |
|
|
| ### Step 3 β Wait for the build |
|
|
| The first build takes **5β8 minutes** (downloading Ubuntu + XFCE packages). |
| Watch the **Build Logs** tab in the Space UI. |
|
|
| ### Step 4 β Access your desktop |
|
|
| Once the Space shows **Running**, click the **App** tab, or open: |
|
|
| ``` |
| https://<username>-<spacename>.hf.space |
| ``` |
|
|
| Click **π₯ Launch Desktop** to open the noVNC browser desktop. |
|
|
| --- |
|
|
| ## π₯ Browser Desktop Access |
|
|
| | URL | Purpose | |
| |---|---| |
| | `https://β¦hf.space/` | Launcher page (recommended) | |
| | `https://β¦hf.space/vnc/vnc.html` | noVNC direct (raw interface) | |
| | `https://β¦hf.space/dashboard` | System stats dashboard | |
|
|
| The launcher page auto-detects your Space's hostname and builds the correct |
| WebSocket URL for noVNC β this is important because HF Spaces use Cloudflare |
| proxying where the port is always 443 externally. |
|
|
| ### Mobile browsers |
|
|
| noVNC works on mobile. Use the scale/resize button (β€’) in the noVNC toolbar |
| to fit the 1280Γ720 desktop to your screen. |
|
|
| --- |
|
|
| ## πΎ Persistent Storage |
|
|
| All state lives under `/data` (Hugging Face's persistent volume): |
|
|
| ``` |
| /data/ |
| βββ home/ β ubuntu user home (~/.bashrc, Desktop, etc.) |
| βββ workspace/ β your project files (persists forever) |
| βββ downloads/ β browser and wget downloads |
| βββ firefox/ β Firefox profile (bookmarks, passwords, etc.) |
| βββ xfce/ β XFCE session config, wallpaper, themes |
| βββ vnc/ β VNC server state + xstartup |
| βββ logs/ β all service logs |
| βββ cache/ β app-level cache |
| ``` |
|
|
| > **Note:** You must enable **Persistent Storage** in your Space settings. |
| > Without it `/data` is ephemeral and resets on every restart. |
|
|
| --- |
|
|
| ## βοΈ PRoot-Distro Similarities |
|
|
| This Space simulates the Termux + PRoot-Distro workflow: |
|
|
| | Termux / PRoot | This Space | |
| |---|---| |
| | `pkg install proot-distro` | Base Docker layer | |
| | `proot-distro install ubuntu` | `FROM ubuntu:24.04` in Dockerfile | |
| | `proot-distro login ubuntu` | Container starts automatically | |
| | `~` (Termux home) | `/data/home` (persisted) | |
| | Internal storage | `/data/workspace` | |
|
|
| The key difference is that this runs Docker natively (not PRoot), giving full |
| kernel-level isolation without the overhead of a userspace chroot. |
|
|
| --- |
|
|
| ## π§ Configuration |
|
|
| ### Environment variables (set in Space settings) |
|
|
| | Variable | Default | Description | |
| |---|---|---| |
| | `VNC_PASSWORD` | _(empty)_ | Set a VNC password (optional; localhost-only anyway) | |
| | `RESOLUTION` | `1280x720` | Desktop resolution | |
| | `COLOR_DEPTH` | `16` | VNC colour depth (16 or 24) | |
|
|
| ### Changing resolution |
|
|
| Edit `supervisord.conf`, update the Xvnc command: |
|
|
| ```ini |
| command=Xvnc :1 -geometry 1920x1080 -depth 24 ... |
| ``` |
|
|
| --- |
|
|
| ## π Troubleshooting |
|
|
| ### Desktop doesn't load / black screen |
|
|
| 1. Open the **Dashboard** β check all services show **Running** |
| 2. Check **Xvnc** and **XFCE4** logs for errors |
| 3. Try restarting XFCE4 from the dashboard restart button |
|
|
| ### "Failed to connect to server" in noVNC |
|
|
| - Make sure you're using the **launcher page** (`/`) not a hard-coded URL |
| - The WebSocket path must be `/websockify` β check the URL bar in noVNC shows the correct host |
|
|
| ### Space keeps sleeping |
|
|
| HF free CPU Spaces sleep after ~15 min of no browser traffic. This is expected. |
| Wake it by opening the Space URL. Your `/data` files are always preserved. |
|
|
| ### High memory usage |
|
|
| XFCE4 uses ~300β400 MB at idle. With Firefox open, expect 800 MB+. The free |
| CPU tier has 16 GB RAM, so this is fine. If you see OOM kills, close unused |
| browser tabs in the desktop. |
|
|
| ### Logs |
|
|
| All logs are in `/data/logs/` and viewable from the Dashboard log viewer: |
|
|
| ``` |
| /data/logs/supervisord.log |
| /data/logs/xvnc.log / xvnc_err.log |
| /data/logs/xfce4.log / xfce4_err.log |
| /data/logs/websockify.log |
| /data/logs/dashboard.log |
| /data/logs/nginx.log / nginx_error.log |
| ``` |
|
|
| --- |
|
|
| ## π Architecture |
|
|
| ``` |
| Browser (HTTPS :443) |
| β |
| βΌ |
| nginx :7860 (HF Spaces default port) |
| ββ / ββββββββββββββββββββββββ Launcher HTML (auto-builds WSS URL) |
| ββ /vnc/ βββββββββββββββββββ noVNC static assets |
| ββ /websockify βββββββββββββ WebSocket proxy βββΊ websockify :6080 |
| β β |
| β Xvnc :5901 |
| β XFCE4 session |
| ββ /dashboard ββββββββββββββ Flask app :5000 |
| ββ /api/ βββββββββββββββββββ Flask REST API :5000 |
| ``` |
|
|
| --- |
|
|
| ## π Licence |
|
|
| MIT β use freely, no warranties. |
|
|