File size: 3,217 Bytes
8a7a0c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# =============================================================================
# Linux Desktop (Fluxbox + TigerVNC) for Hugging Face Spaces
# Headless container orchestration with hardened startup & resource shaping.
# =============================================================================
FROM debian:bookworm-slim

ENV DEBIAN_FRONTEND=noninteractive \
    LANG=C.UTF-8 \
    LC_ALL=C.UTF-8 \
    HOME=/home/user \
    USER=user \
    DISPLAY=:99

# -----------------------------------------------------------------------------
# System packages
#  - tigervnc-standalone-server: provides Xvnc (single-layer X11 + VNC server)
#  - fluxbox: lightweight window manager (low RAM footprint)
#  - novnc + websockify: browser <-> VNC bridge
#  - socat: used for the temporary HTTP "fast-ack" health-check responder
#  - xterm / dbus-x11 / x11-utils: minimal desktop tooling
# -----------------------------------------------------------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
        tigervnc-standalone-server \
        tigervnc-common \
        fluxbox \
        xterm \
        x11-utils \
        x11-xserver-utils \
        dbus-x11 \
        novnc \
        websockify \
        python3 \
        python3-numpy \
        socat \
        procps \
        net-tools \
        ca-certificates \
        curl \
        sudo \
        nano \
    && rm -rf /var/lib/apt/lists/*

# -----------------------------------------------------------------------------
# Non-root user (HF Spaces best practice)
# -----------------------------------------------------------------------------
RUN useradd -m -u 1000 -s /bin/bash user && \
    echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

# -----------------------------------------------------------------------------
# noVNC web assets — expose at a stable path so websockify can serve them
# -----------------------------------------------------------------------------
RUN ln -sf /usr/share/novnc /novnc && \
    ln -sf /usr/share/novnc/vnc.html /usr/share/novnc/index.html

# -----------------------------------------------------------------------------
# Fluxbox autostart hook — keep the WM lean (no menu daemons, no compositor)
# -----------------------------------------------------------------------------
RUN mkdir -p /home/user/.fluxbox && \
    echo "xsetroot -solid '#1f2937'" > /home/user/.fluxbox/startup && \
    echo "xterm -geometry 100x30+50+50 -fa 'Monospace' -fs 11 &" >> /home/user/.fluxbox/startup && \
    echo "exec fluxbox" >> /home/user/.fluxbox/startup && \
    chmod +x /home/user/.fluxbox/startup && \
    chown -R user:user /home/user

# -----------------------------------------------------------------------------
# Entry-point script (engineering-hardened startup sequence)
# -----------------------------------------------------------------------------
COPY start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh && \
    chown user:user /usr/local/bin/start.sh

# Make /tmp/.X11-unix writable by the unprivileged user (Xvnc needs this)
RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix

USER user
WORKDIR /home/user

EXPOSE 7860

CMD ["/usr/local/bin/start.sh"]