Skip to content

Commit 02b7afa

Browse files
committed
fix(docker): install Claude CLI and create workspace directory
- Install Claude Code CLI via npm in Dockerfile (fixes ProcessTransport error) - Create /app/workspace directory with git init (fixes missing cwd) - Add nodejs, npm, curl, ca-certificates to container deps - Make ANTHROPIC_API_KEY required for Docker (no interactive login) - Document Docker auth requirements in docs/docker.md - Clarify ANTHROPIC_API_KEY usage in .env.example Fixes #18
1 parent c4f5927 commit 02b7afa

File tree

4 files changed

+58
-17
lines changed

4 files changed

+58
-17
lines changed

.env.example

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ DISCORD_TOKEN=your_bot_token_here
1818
# https://discord.com/developers/applications -> Your App -> General Information -> Application ID
1919
APPLICATION_ID=your_application_id_here
2020

21+
# Anthropic API Key
22+
# - REQUIRED when running in Docker (the Claude CLI inside the container uses
23+
# this to authenticate — you cannot run `claude /login` in a container)
24+
# - Optional for native installs (enables dynamic model discovery; without it
25+
# the bot falls back to a hardcoded model list)
26+
# Get yours at: https://console.anthropic.com/settings/keys
2127
ANTHROPIC_API_KEY=your_anthropic_api_key_here
28+
2229
# ===================================
2330
# OPTIONAL CONFIGURATION
2431
# ===================================
@@ -27,12 +34,6 @@ ANTHROPIC_API_KEY=your_anthropic_api_key_here
2734
# Defaults to current directory if not set
2835
# WORK_DIR=/path/to/your/project
2936

30-
# Anthropic API Key (for dynamic model discovery)
31-
# If set, the bot fetches available models from the Anthropic API at startup
32-
# and refreshes every hour. Without this, it uses a hardcoded model list.
33-
# Get yours at: https://console.anthropic.com/settings/keys
34-
# ANTHROPIC_API_KEY=sk-ant-...
35-
3637
# Your Discord User ID for @mentions when Claude finishes
3738
# Right-click your profile in Discord -> Copy User ID (requires Developer Mode)
3839
# USER_ID=your_discord_user_id

Dockerfile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
# Claude Code Discord Bot
2-
# Multi-stage build for optimized production image
2+
# Optimized production image with Claude CLI
33

44
FROM denoland/deno:latest
55

6+
# Build arguments for user UID/GID (match host user to avoid permission issues)
7+
ARG USER_ID=1000
8+
ARG GROUP_ID=1000
9+
610
# Set working directory
711
WORKDIR /app
812

913
# Set environment variable to indicate Docker container
1014
ENV DOCKER_CONTAINER=true
1115

12-
# Install git (required for branch tracking and version checks)
16+
# Install system dependencies
1317
USER root
1418
RUN apt-get update && \
15-
apt-get install -y git && \
19+
apt-get install -y --no-install-recommends git curl ca-certificates nodejs npm && \
1620
rm -rf /var/lib/apt/lists/*
1721

18-
# Create non-root user for security
19-
RUN groupadd -r claude && useradd -r -g claude claude
22+
# Create non-root user with home directory (needed for Claude CLI config)
23+
RUN groupadd -r -g ${GROUP_ID} claude && \
24+
useradd -r -u ${USER_ID} -g claude -m claude
25+
26+
# Install Claude Code CLI globally via npm
27+
RUN npm install -g @anthropic-ai/claude-code && \
28+
npm cache clean --force
29+
30+
# Verify claude binary is accessible
31+
RUN claude --version
2032

21-
# Copy all source files first (as root)
33+
# Copy all source files (as root)
2234
COPY . .
2335

2436
# Remove lockfile if present (avoid version conflicts)
@@ -27,11 +39,13 @@ RUN rm -f deno.lock
2739
# Initialize git repo in container (for non-git workspaces)
2840
RUN git init && git config user.email "bot@claude.local" && git config user.name "Claude Bot"
2941

30-
# Pre-compile dependencies as root (before switching user)
42+
# Pre-compile Deno dependencies
3143
RUN deno cache --no-lock index.ts
3244

33-
# Create data directory for persistence and set ownership
34-
RUN mkdir -p .bot-data && chown -R claude:claude /app
45+
# Create data directory for persistence + workspace dir, set ownership
46+
RUN mkdir -p .bot-data /app/workspace && \
47+
cd /app/workspace && git init && git config user.email "bot@claude.local" && git config user.name "Claude Bot" && \
48+
chown -R claude:claude /app /home/claude
3549

3650
# Switch to non-root user
3751
USER claude

docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Claude Code Discord Bot - Docker Compose Configuration
22
# Quick start: docker compose up -d
33
#
4+
# IMPORTANT: The ANTHROPIC_API_KEY in your .env file is required for Docker.
5+
# The Claude CLI inside the container uses it to authenticate with Anthropic.
6+
# (Unlike native installs, you cannot run `claude /login` inside the container.)
7+
#
48
# To use the pre-built image from GitHub Container Registry (recommended):
59
# 1. Comment out the 'build' section below
610
# 2. Uncomment the 'image' line
@@ -18,10 +22,11 @@ services:
1822
restart: unless-stopped
1923

2024
# Environment variables (use .env file or set here)
25+
# ANTHROPIC_API_KEY is required in Docker — it authenticates the Claude CLI
2126
environment:
2227
- DISCORD_TOKEN=${DISCORD_TOKEN}
2328
- APPLICATION_ID=${APPLICATION_ID}
24-
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
29+
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
2530
- WORK_DIR=${WORK_DIR:-/app/workspace}
2631
- USER_ID=${USER_ID:-}
2732
- CATEGORY_NAME=${CATEGORY_NAME:-claude-code}

docs/docker.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
docker compose up -d
77
```
88

9-
Make sure your `.env` file is in the project root with all required variables. See [Installation](installation.md) for `.env` setup.
9+
Make sure your `.env` file is in the project root with **all required variables**:
10+
- `DISCORD_TOKEN` — your Discord bot token
11+
- `APPLICATION_ID` — your Discord application ID
12+
- `ANTHROPIC_API_KEY`**required in Docker** (the Claude CLI inside the container uses this to authenticate)
13+
14+
See [Installation](installation.md) for full `.env` setup.
1015

1116
## Docker Compose
1217

@@ -82,9 +87,25 @@ This checks for new images every 5 minutes and restarts the bot automatically.
8287
8388
The Dockerfile builds on `denoland/deno:latest` and adds:
8489

90+
- **Claude Code CLI** (`@anthropic-ai/claude-code`) — required for Claude interactions
8591
- **Git** (required for branch tracking and version checks)
92+
- **Node.js / npm** (used to install the Claude CLI)
8693
- **Deno cached dependencies** from `deno.json`
8794

95+
## Authentication in Docker
96+
97+
Unlike native installs where you can run `claude /login` interactively, Docker containers authenticate via the `ANTHROPIC_API_KEY` environment variable.
98+
99+
**`ANTHROPIC_API_KEY` is required when running in Docker.** The Claude CLI inside the container reads this key to authenticate with Anthropic. Without it, any `/claude` or `/ask` command will fail with a `ProcessTransport is not ready for writing` error.
100+
101+
Make sure your `.env` file includes a valid key:
102+
103+
```env
104+
ANTHROPIC_API_KEY=sk-ant-...
105+
```
106+
107+
Get your API key from [console.anthropic.com/settings/keys](https://console.anthropic.com/settings/keys).
108+
88109
## Resource Limits
89110

90111
For production, consider setting resource limits:

0 commit comments

Comments
 (0)