Download Dockerfile from AZILS/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/AZILS/opencode/resolve/abc9b60f4eabe5f6cf3eead8bd937722b67f1df3/Dockerfile
- Command line
-
hf download hf://spaces/AZILS/opencode@abc9b60f4eabe5f6cf3eead8bd937722b67f1df3/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/AZILS/opencode/resolve/abc9b60f4eabe5f6cf3eead8bd937722b67f1df3/Dockerfile
1.46 kB
| # OpenCode on Hugging Face Spaces (Docker) | |
| # 使用官方安装脚本安装 opencode,并以 headless HTTP server 方式暴露 API | |
| FROM ubuntu:24.04 | |
| # 避免交互式提示 | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # 安装依赖:安装脚本需要 curl、tar(Linux 解压) | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ca-certificates \ | |
| curl \ | |
| tar \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # 不创建新用户(HF 构建环境可能已有 UID 1000),改为以 root 安装到 /home/user 再 chown | |
| RUN mkdir -p /home/user/app | |
| # 使用官方安装脚本安装 opencode 到 /home/user/.opencode/bin | |
| RUN HOME=/home/user curl -fsSL https://opencode.ai/install | bash -s -- --no-modify-path | |
| # 将 /home/user 归属给 UID 1000(HF Spaces 运行时使用 UID 1000) | |
| RUN chown -R 1000:1000 /home/user | |
| ENV HOME=/home/user | |
| ENV PATH=/home/user/.opencode/bin:$PATH | |
| # 以 UID 1000 运行(符合 HF Spaces 要求) | |
| USER 1000 | |
| WORKDIR $HOME/app | |
| # 验证 opencode 可用(使用绝对路径,因 USER 1000 时 PATH 可能未包含安装目录) | |
| RUN /home/user/.opencode/bin/opencode --version | |
| # Hugging Face Spaces 默认暴露 7860 | |
| EXPOSE 7860 | |
| # 启动 headless HTTP server,监听 0.0.0.0 以便 Space 代理访问 | |
| # 使用绝对路径,避免 UID 1000 下 PATH 未生效 | |
| # 文档与 API: /doc 为 OpenAPI 3.1 规范 | |
| CMD ["/home/user/.opencode/bin/opencode", "serve", "--port", "7860", "--hostname", "0.0.0.0"] | |