# 使用官方 NapCat 镜像,因为它已经配置好了复杂的 Wine 和 QQ 环境 FROM mlikiowa/napcat-docker:latest USER root # 1. 环境变量 ENV TZ=Asia/Shanghai \ PORT=7860 # 2. 注入启动逻辑 (核心:修改官方 entrypoint.sh) # 我们直接在脚本第二行插入 Python 转发器、配置锁定和权限修复逻辑 RUN sed -i '2i \ # --- 启动纯 Python 转发器 (7860 -> 6099) --- \n\ python3 -c "import socket,threading; \ def p(s,d): \ try: \ while 1: \ data=s.recv(4096); \ if not data:break; \ d.sendall(data) \ except:pass \ finally: \ try:s.close() \ except:pass; \ try:d.close() \ except:pass; \ def f(): \ s=socket.socket(); \ s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1); \ s.bind((\"0.0.0.0\",7860)); \ s.listen(20); \ while 1: \ c,_=s.accept(); \ t=socket.socket(); \ try: \ t.connect((\"127.0.0.1\",6099)); \ threading.Thread(target=p,args=(c,t),daemon=True).start(); \ threading.Thread(target=p,args=(t,c),daemon=True).start(); \ except: \ c.sendall(b\"HTTP/1.1 200 OK\\r\\n\\r\\nNapCat Initializing...\"); \ c.close() \ threading.Thread(target=f,daemon=True).start()" & \n\ # --- 强制覆盖 WebUI 端口配置 --- \n\ mkdir -p /app/napcat/config /app/.config/QQ; \n\ echo "{\\"host\\":\\"0.0.0.0\\",\\"port\\":6099,\\"token\\":\\"\\",\\"loginRate\\":2}" > /app/napcat/config/webui.json; \n\ chmod -R 777 /app/napcat/config /app/.config/QQ; \n\ echo "--- [System] HF Space Injector Ready ---"' /app/entrypoint.sh # 3. 权限大赦:确保 Wine 运行时的用户能读写目录 RUN chmod -R 777 /app/napcat /app/.config # 4. 工作目录与暴露端口 WORKDIR /app EXPOSE 7860 # 5. 关键:直接运行官方入口 # 这样能保证 Wine、Xvfb 的 PID 1 信号管理完全由官方逻辑处理,不会报 Runtime Error ENTRYPOINT ["bash", "/app/entrypoint.sh"]