FROM docker.io/library/python:3.10 # 1. 设置清晰的工作目录 WORKDIR /app # 2. 安装基础依赖 RUN pip install --no-cache-dir pipx uvicorn fastapi && pipx ensurepath # 3. 克隆源码并进行源码安装 RUN git clone https://github.com/Panniantong/agent-reach.git /opt/agent-reach RUN pip install -e /opt/agent-reach # 4. 【核心】直接在容器内生成 app.py 接口文件 RUN echo 'import os, subprocess\n\ from fastapi import FastAPI, Query\n\ import uvicorn\n\ app = FastAPI()\n\ @app.get("/")\n\ def index():\n\ return {"status": "running", "msg": "Welcome to Agent-Reach API"}\n\ @app.get("/cmd")\n\ def run_command(q: str = Query(..., description="command")):\n\ try:\n\ result = subprocess.check_output(q, shell=True, stderr=subprocess.STDOUT, text=True)\n\ return {"code": 0, "output": result}\n\ except subprocess.CalledProcessError as e:\n\ return {"code": 1, "output": e.output}\n\ if __name__ == "__main__":\n\ uvicorn.run(app, host="0.0.0.0", port=7860)\n\ ' > /app/app.py # 5. 授予 Hugging Face 默认用户完全的读写权限 RUN chmod -R 777 /app /opt/agent-reach # 6. 声明端口 EXPOSE 7860 # 7. 绝对路径启动,彻底杜绝 No such file 错误 CMD ["python", "/app/app.py"]