Fix Docker startup issues

- Change executable from claude-code to claude in startup.sh
- Fix .env parsing to handle comments using set -a/source
- Add explicit PATH for npm global binaries in Dockerfile
- Update scratchpad.md with fix documentation
This commit is contained in:
Vishal Jain 2025-06-12 11:10:32 +01:00
parent 0ec49a426a
commit 7c14a75afc
7 changed files with 57 additions and 39 deletions

View File

@ -1,11 +1,12 @@
# ABOUTME: Environment variables for Claude Docker # ABOUTME: Environment variables for Claude Docker
# ABOUTME: Copy this to ~/.claude-docker/.env and fill in your values # ABOUTME: Copy this to ~/.claude-docker/.env and fill in your values
# Anthropic API key for Claude Code # Optional: Anthropic API key (only needed if not using subscription auth)
ANTHROPIC_API_KEY=your_anthropic_api_key_here # ANTHROPIC_API_KEY=sk-ant-your_anthropic_api_key_here
# Twilio credentials for SMS notifications # Optional: Twilio credentials for SMS notifications via MCP
TWILIO_ACCOUNT_SID=your_twilio_account_sid # TWILIO_ACCOUNT_SID=your_twilio_sid_here
TWILIO_AUTH_TOKEN=your_twilio_auth_token # TWILIO_API_KEY=your_twilio_api_key_here
TWILIO_PHONE_NUMBER=+1234567890 # Your Twilio phone number # TWILIO_API_SECRET=your_twilio_api_secret_here
YOUR_PHONE_NUMBER=+1234567890 # Your personal phone to receive SMS # TWILIO_FROM_NUMBER=+1234567890 # Your Twilio phone number
# TWILIO_TO_NUMBER=+1234567890 # Your personal phone to receive SMS

View File

@ -17,8 +17,11 @@ WORKDIR /app
# Install Claude Code globally # Install Claude Code globally
RUN npm install -g @anthropic-ai/claude-code RUN npm install -g @anthropic-ai/claude-code
# Ensure npm global bin is in PATH
ENV PATH="/usr/local/bin:${PATH}"
# Install Twilio MCP server # Install Twilio MCP server
RUN npm install -g @twilioalpha/mcp-server-twilio RUN npm install -g @twilio-alpha/mcp
# Create directories for configuration # Create directories for configuration
RUN mkdir -p /app/config /app/.claude RUN mkdir -p /app/config /app/.claude

View File

@ -23,15 +23,20 @@ A Docker container setup for running Claude Code with full autonomous permission
```bash ```bash
# Edit ~/.claude-docker/.env with your keys # Edit ~/.claude-docker/.env with your keys
ANTHROPIC_API_KEY=your_anthropic_key ANTHROPIC_API_KEY=your_anthropic_key
# For Twilio MCP integration:
TWILIO_ACCOUNT_SID=your_twilio_sid TWILIO_ACCOUNT_SID=your_twilio_sid
TWILIO_AUTH_TOKEN=your_twilio_token TWILIO_API_KEY=your_twilio_api_key
TWILIO_API_SECRET=your_twilio_api_secret
TWILIO_FROM_NUMBER=your_twilio_number TWILIO_FROM_NUMBER=your_twilio_number
TWILIO_TO_NUMBER=your_phone_number TWILIO_TO_NUMBER=your_phone_number
``` ```
> **Note**: Twilio MCP requires API Key/Secret instead of Auth Token. Create API keys in your Twilio Console under Account → API keys & tokens.
3. **Use from any project directory:** 3. **Use from any project directory:**
```bash ```bash
claude claude-docker
``` ```
## Features ## Features
@ -89,8 +94,8 @@ The setup creates `~/.claude-docker/` with:
## Requirements ## Requirements
- Docker installed and running - Docker installed and running
- Anthropic API key - Anthropic API key (or Claude subscription)
- (Optional) Twilio account for SMS notifications - (Optional) Twilio account with API Key/Secret for SMS notifications
## Next Steps ## Next Steps

View File

@ -1,14 +1,16 @@
{ {
"mcpServers": { "mcpServers": {
"twilio": { "twilio": {
"command": "node", "command": "npx",
"args": ["/usr/lib/node_modules/@twilioalpha/mcp-server-twilio/build/index.js"], "args": [
"env": { "-y",
"TWILIO_ACCOUNT_SID": "${TWILIO_ACCOUNT_SID}", "@twilio-alpha/mcp",
"TWILIO_AUTH_TOKEN": "${TWILIO_AUTH_TOKEN}", "${TWILIO_ACCOUNT_SID}/${TWILIO_API_KEY}:${TWILIO_API_SECRET}",
"TWILIO_PHONE_NUMBER": "${TWILIO_PHONE_NUMBER}", "--services",
"YOUR_PHONE_NUMBER": "${YOUR_PHONE_NUMBER}" "twilio_api_v2010",
} "--tags",
"Api20100401Message"
]
} }
} }
} }

View File

@ -59,15 +59,21 @@ Building a Docker container that runs Claude Code with full autonomous permissio
## Notes & Context ## Notes & Context
- Repository: https://github.com/VishalJ99/claude-docker - Repository: https://github.com/VishalJ99/claude-docker
- Using --dangerously-skip-permissions flag for full autonomy - Using --dangerously-skip-permissions flag for full autonomy
- Twilio MCP server runs alongside Claude Code in container - Twilio MCP server runs via Claude's MCP config (not as separate process)
- Uses @twilio-alpha/mcp package with API Key/Secret authentication
- Container auto-removes on exit for clean state - Container auto-removes on exit for clean state
- Project directory mounted at /workspace - Project directory mounted at /workspace
- Need to research Claude dev container's init-firewall.sh implementation - Need to research Claude dev container's init-firewall.sh implementation
- Need to research their history persistence mechanism - Need to research their history persistence mechanism
- **Fixed startup issues (Dec 2024):**
- Changed executable from `claude-code` to `claude` in startup.sh
- Fixed .env parsing to handle comments properly using `set -a`/`source`
- Added explicit PATH for npm global binaries
- Maintained separation: `claude-docker` (host) vs `claude` (container)
## Quick References ## Quick References
- Install: `./scripts/install.sh` - Install: `./scripts/install.sh`
- Usage: `claude` (from any project directory) - Usage: `claude-docker` (from any project directory)
- Config: `~/.claude-docker/.env` - Config: `~/.claude-docker/.env`
- Repo: https://github.com/VishalJ99/claude-docker - Repo: https://github.com/VishalJ99/claude-docker
- Claude dev container: https://github.com/anthropics/claude-code/tree/main/.devcontainer - Claude dev container: https://github.com/anthropics/claude-code/tree/main/.devcontainer

View File

@ -16,15 +16,15 @@ if [ ! -f "$HOME/.claude-docker/.env" ]; then
fi fi
# Add alias to .zshrc # Add alias to .zshrc
ALIAS_LINE="alias claude='$PROJECT_ROOT/scripts/claude-docker.sh'" ALIAS_LINE="alias claude-docker='$PROJECT_ROOT/scripts/claude-docker.sh'"
if ! grep -q "alias claude=" "$HOME/.zshrc"; then if ! grep -q "alias claude-docker=" "$HOME/.zshrc"; then
echo "" >> "$HOME/.zshrc" echo "" >> "$HOME/.zshrc"
echo "# Claude Docker alias" >> "$HOME/.zshrc" echo "# Claude Docker alias" >> "$HOME/.zshrc"
echo "$ALIAS_LINE" >> "$HOME/.zshrc" echo "$ALIAS_LINE" >> "$HOME/.zshrc"
echo "✓ Added 'claude' alias to .zshrc" echo "✓ Added 'claude-docker' alias to .zshrc"
else else
echo "✓ Claude alias already exists in .zshrc" echo "✓ Claude-docker alias already exists in .zshrc"
fi fi
# Make scripts executable # Make scripts executable
@ -35,6 +35,7 @@ echo ""
echo "Installation complete! 🎉" echo "Installation complete! 🎉"
echo "" echo ""
echo "Next steps:" echo "Next steps:"
echo "1. Edit $HOME/.claude-docker/.env with your API keys" echo "1. (Optional) Edit $HOME/.claude-docker/.env with your API keys"
echo "2. Run 'source ~/.zshrc' or start a new terminal" echo "2. Run 'source ~/.zshrc' or start a new terminal"
echo "3. Navigate to any project and run 'claude' to start" echo "3. Navigate to any project and run 'claude-docker' to start"
echo "4. If no API key, Claude will prompt for interactive authentication"

View File

@ -1,23 +1,23 @@
#!/bin/bash #!/bin/bash
# ABOUTME: Startup script for Claude Code container with MCP server # ABOUTME: Startup script for Claude Code container with MCP server
# ABOUTME: Launches Twilio MCP server then starts Claude Code with permissions bypass # ABOUTME: Configures environment and starts Claude Code with Twilio MCP integration
# Load environment variables from .env if it exists # Load environment variables from .env if it exists
if [ -f /app/.env ]; then if [ -f /app/.env ]; then
export $(cat /app/.env | grep -v '^#' | xargs) set -a
source /app/.env 2>/dev/null || true
set +a
fi fi
# Start Twilio MCP server in the background
echo "Starting Twilio MCP server..."
npx @twilioalpha/mcp-server-twilio &
MCP_PID=$!
# Give MCP server time to start
sleep 2
# Configure Claude Code to use the MCP server # Configure Claude Code to use the MCP server
export CLAUDE_MCP_CONFIG=/app/config/mcp-config.json export CLAUDE_MCP_CONFIG=/app/config/mcp-config.json
# Start Claude Code with permissions bypass # Start Claude Code with permissions bypass
echo "Starting Claude Code..." echo "Starting Claude Code..."
exec claude-code --dangerously-skip-permissions "$@" if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_API_KEY" ]; then
echo "Twilio MCP integration enabled"
else
echo "No Twilio credentials found, MCP features will be unavailable"
fi
echo "Note: If prompted for authentication, follow the interactive prompts"
exec claude --dangerously-skip-permissions "$@"