Claude-cli / Dockerfile
kovinape's picture
Update Dockerfile
08e0270 verified
# ─────────────────────────────────────────────────────────────
# HF Docker Space β€” Ollama + Claude Code (web terminal)
# Exposed port : 7860 (only port HF Spaces forwards)
# Web terminal : ttyd (full interactive Claude CLI in browser)
# Model : gpt-oss:20b via Ollama Anthropic-compat API
# ─────────────────────────────────────────────────────────────
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
# ── System packages ──────────────────────────────────────────
RUN apt-get update && apt-get install -y \
curl wget git ca-certificates gnupg zstd \
&& \
# Node.js 20 LTS (needed by Claude Code CLI)
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs && \
# Ollama
curl -fsSL https://ollama.com/install.sh | sh && \
# ttyd β€” browser-based terminal (static binary, no extra deps)
wget -q -O /usr/local/bin/ttyd \
https://github.com/tsl0922/ttyd/releases/download/1.7.7/ttyd.x86_64 && \
chmod +x /usr/local/bin/ttyd && \
rm -rf /var/lib/apt/lists/*
# ── Claude Code CLI (global npm install as root) ─────────────
RUN npm install -g @anthropic-ai/claude-code
# ── HF Spaces requires UID 1000 ──────────────────────────────
RUN useradd -m -u 1000 user
# Switch to user 1000 for all runtime operations
USER user
ENV HOME=/home/user
ENV PATH=/home/user/.local/bin:/usr/local/bin:$PATH
# ── Point Claude Code at local Ollama (no Anthropic key needed)
ENV ANTHROPIC_AUTH_TOKEN=ollama
ENV ANTHROPIC_API_KEY=ollama
ENV ANTHROPIC_BASE_URL=http://localhost:11434
# Ollama: listen on all interfaces so internal health-checks work
ENV OLLAMA_HOST=0.0.0.0:11434
# Store models under user home (writable at runtime)
ENV OLLAMA_MODELS=/home/user/.ollama/models
# Skip Claude Code's first-run login wizard
ENV CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
WORKDIR /home/user
# Copy startup script
COPY --chown=user entrypoint.sh /home/user/entrypoint.sh
RUN chmod +x /home/user/entrypoint.sh
# ── Only one port is forwarded by HF Spaces ──────────────────
EXPOSE 7860
CMD ["/home/user/entrypoint.sh"]