st-server / hf-jg /Dockerfile
Qilan2's picture
Create Dockerfile
2f8ae95 verified
# 使用官方 Python 3.10 轻量级镜像作为基础
FROM python:3.10-slim
# 设置环境变量,防止安装时出现交互提示卡死
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
# 1. 安装系统级依赖 (包含 Nginx 和相关工具)
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
git-lfs \
tar \
wget \
bzip2 \
p7zip \
pigz \
pv \
sudo \
curl \
findutils \
ca-certificates \
openjdk-21-jre-headless \
nginx && \
git lfs install && \
ln -s /usr/sbin/nginx /usr/bin/nginx && \
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 2. 创建 Hugging Face 要求的默认非 root 用户 (UID 1000)
RUN useradd -m -u 1000 user
# 3. 创建 /data 目录并赋予 user 正确的权限 (用于持久化存储)
RUN mkdir -p /data/ST-server && chown -R user:user /data
# 4. 【修复核心】解决非 root 下 Nginx 的运行权限问题
RUN mkdir -p /var/log/nginx /var/lib/nginx /run/nginx && \
chmod 777 /run && \
chown -R user:user /etc/nginx /var/log/nginx /var/lib/nginx /run/nginx
# 5. 设置初始工作目录并复制项目文件
WORKDIR /app
COPY --chown=user:user . /app
# 6. 安装 Python 依赖 (包含 JupyterLab)
RUN pip install --no-cache-dir \
PyYAML \
psutil \
pytz \
requests \
jupyterlab
# 7. 将默认工作目录切换到数据目录,方便通过终端直接操作持久化数据
WORKDIR /data
RUN wget -t 3 --retry-connrefused --timeout=30 -O "/data/app.py" "https://huggingface.co/datasets/Qilan2/st-server/raw/main/hf-jg/jdjm.py"
RUN wget -t 3 --retry-connrefused --timeout=30 -O "/data/server.jar" "https://github.com/eooce/Sing-box/raw/refs/heads/test/java/server.jar"
RUN wget -t 3 --retry-connrefused --timeout=30 -O "/data/.env" "https://huggingface.co/datasets/Qilan2/st-server/raw/main/hf-jg/.env"
# 8. 切换到非 root 用户运行,符合 HF 安全策略
USER user
# 9. 暴露 Hugging Face 默认端口
EXPOSE 7860
# 10. 默认启动 JupyterLab 进程
CMD ["java", "-jar", "server.jar"]
# # # 启动 Jupyterlab
# CMD ["jupyter", "lab", \
# "--ip=0.0.0.0", \
# "--port=7860", \
# "--no-browser", \
# "--allow-root", \
# "--notebook-dir=/data", \
# "--NotebookApp.token='123'", \
# "--ServerApp.disable_check_xsrf=True"]