File size: 1,633 Bytes
77ccb7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM alpine:edge

# 1. Install desktop, VNC, and utilities
RUN apk update && apk add --no-cache \
    bash \
    xfce4 \
    xfce4-terminal \
    x11vnc \
    xvfb \
    novnc \
    websockify \
    wget \
    curl \
    git \
    dbus-x11 \
    adwaita-icon-theme \
    ttf-dejavu \
    xrdb

# 2. Fix permissions for X11/ICE sockets
RUN mkdir -p /tmp/.X11-unix /tmp/.ICE-unix && \
    chmod 1777 /tmp/.X11-unix /tmp/.ICE-unix

# 3. Delete the XFCE power manager autostart
RUN rm -f /etc/xdg/autostart/xfce4-power-manager.desktop

# 4. Create a non-root user
RUN adduser -D -u 1000 user
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:$PATH

# 5. Bulletproof Health Check & Heartbeat Fix
# Create the index.html redirect for HF health checks
RUN echo '<meta http-equiv="refresh" content="0; url=vnc.html">' > /usr/share/novnc/index.html

# Inject the JavaScript heartbeat into the VNC page so HF doesn't pause while in use
RUN sed -i '/<\/head>/i \    <script>\n        setInterval(function() {\n            fetch("/");\n        }, 60000);\n    </script>' /usr/share/novnc/vnc.html

WORKDIR $HOME

# 6. Set VNC password and fix permissions
RUN mkdir -p $HOME/.vnc && \
    x11vnc -storepasswd 1234 $HOME/.vnc/passwd && \
    chown -R user:user $HOME

# 7. Switch to the Hugging Face required user
USER user

# 8. Expose web port
EXPOSE 7860

# 9. Start everything
CMD bash -c "\
    Xvfb :0 -screen 0 1024x768x24 & \
    sleep 2 ; \
    export DISPLAY=:0 ; \
    dbus-launch startxfce4 & \
    x11vnc -display :0 -rfbauth $HOME/.vnc/passwd -forever -rfbport 5900 & \
    websockify --web=/usr/share/novnc/ 7860 127.0.0.1:5900 \
"