test / Dockerfile
chipling's picture
Update Dockerfile
6b65116 verified
# Use the latest supported python slim image
FROM python:3.9-slim
# 1. Install system dependencies
# We suppress prompts to avoid build errors
ENV DEBIAN_FRONTEND=noninteractive
# Note: Removed 'numpy' from this list.
# Added 'dbus-x11' which is often needed for XFCE to start correctly in containers.
RUN apt-get update && apt-get install -y \
xfce4 \
xfce4-terminal \
xvfb \
x11vnc \
novnc \
websockify \
firefox-esr \
sudo \
curl \
git \
vim \
procps \
dbus-x11 \
&& rm -rf /var/lib/apt/lists/*
# 2. Setup a non-root user (Hugging Face Spaces defaults to UID 1000)
RUN useradd -m -u 1000 user
RUN echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# 3. Set up the working directory
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME
# 4. Install Python dependencies (Numpy goes here!)
RUN pip install --no-cache-dir numpy
# 5. Create the start script
# We configure the VNC and NoVNC connection here
RUN echo '#!/bin/bash\n\
\n\
# Set VNC password (default: password)\n\
export VNC_PASSWD=${VNC_PASSWD:-password}\n\
\n\
# Start Xvfb (Virtual Monitor)\n\
# 1280x720 is a good standard size\n\
Xvfb :1 -screen 0 1280x720x16 &\n\
export DISPLAY=:1\n\
sleep 2\n\
\n\
# Start Window Manager (XFCE)\n\
startxfce4 &\n\
sleep 2\n\
\n\
# Start VNC Server\n\
mkdir -p ~/.vnc\n\
x11vnc -storepasswd "$VNC_PASSWD" ~/.vnc/passwd\n\
x11vnc -display :1 -rfbauth ~/.vnc/passwd -forever -shared -bg\n\
\n\
# Start NoVNC (The Web Interface)\n\
# This bridges the VNC server (5900) to the Web Port (7860)\n\
echo "Starting NoVNC..."\n\
websockify --web /usr/share/novnc/ 7860 localhost:5900\n\
' > start.sh
RUN chmod +x start.sh
# 6. Expose the Hugging Face port
EXPOSE 7860
# 7. Run the start script
CMD ["./start.sh"]