Athena — mahmoud-consultancy/archive/old-docs/DOCKER-CLAUDE.md

Claude Code Docker Setup

This setup allows you to run Claude Code continuously in a Docker container with --allow-all mode enabled to work on the mahmoud-consultancy project infinitely.

Prerequisites

  • Docker and Docker Compose installed
  • Anthropic API key (Get one here)

Quick Start

1. Configure Environment

Copy the example environment file and add your API key:

cp .env.claude.example .env.claude

Edit .env.claude and set your ANTHROPIC_API_KEY:

ANTHROPIC_API_KEY=sk-ant-api03-...

2. Build and Run

Build the Docker image:

docker-compose -f docker-compose.claude.yml build

Start Claude Code worker:

docker-compose -f docker-compose.claude.yml up -d

3. Monitor Claude's Work

View logs in real-time:

docker-compose -f docker-compose.claude.yml logs -f

View recent logs:

docker-compose -f docker-compose.claude.yml logs --tail=100

Management Commands

Stop the container

docker-compose -f docker-compose.claude.yml down

Restart the container

docker-compose -f docker-compose.claude.yml restart

View container status

docker-compose -f docker-compose.claude.yml ps

Access the container shell

docker exec -it claude-mahmoud-consultancy bash

Configuration

Custom Prompt

Edit the CLAUDE_PROMPT variable in .env.claude to customize what Claude works on:

CLAUDE_PROMPT=Review the codebase and fix all TypeScript errors in the frontend

Git Configuration

Claude will make commits on your behalf. Configure git identity in .env.claude:

GIT_EMAIL=your-email@example.com
GIT_NAME=Your Name

Resource Limits

The container is configured with:

  • CPU limit: 2 cores (max), 1 core (reserved)
  • Memory limit: 4GB (max), 2GB (reserved)

Adjust these in docker-compose.claude.yml under deploy.resources if needed.

How It Works

  1. The container runs Claude Code with --allow-all flag, which auto-approves all tool uses
  2. Claude continuously works on the project based on the configured prompt
  3. All changes are made directly to your project directory (mounted as volume)
  4. The container restarts automatically on failure
  5. Git commits are made with the configured identity

Safety Notes

  • Review commits regularly: Claude makes real changes to your codebase
  • Use version control: Always commit your work before starting Claude
  • Monitor resource usage: Claude may use significant API credits
  • Test in a branch: Consider running this on a separate git branch

Troubleshooting

Container keeps restarting

Check logs for errors:

docker-compose -f docker-compose.claude.yml logs

API key errors

Verify your .env.claude file has the correct ANTHROPIC_API_KEY

Permission issues

Ensure the docker-entrypoint.sh is executable:

chmod +x docker-entrypoint.sh

High CPU/Memory usage

Adjust resource limits in docker-compose.claude.yml

Advanced Usage

Run multiple Claude workers

Create multiple docker-compose files with different prompts and container names:

# Worker 1: Frontend tasks
docker-compose -f docker-compose.claude.yml up -d

# Worker 2: Backend tasks (create a separate docker-compose.claude-backend.yml)
docker-compose -f docker-compose.claude-backend.yml up -d

Schedule specific tasks

Use environment variables to set specific tasks:

CLAUDE_PROMPT="Run all tests and fix failing ones" docker-compose -f docker-compose.claude.yml up

Files Created

  • Dockerfile.claude - Docker image definition
  • docker-compose.claude.yml - Docker Compose configuration
  • docker-entrypoint.sh - Startup script that runs Claude
  • .env.claude.example - Example environment configuration
  • DOCKER-CLAUDE.md - This documentation file

Example Workflow

# 1. Setup
cp .env.claude.example .env.claude
# Edit .env.claude with your API key

# 2. Start Claude working on the project
docker-compose -f docker-compose.claude.yml up -d

# 3. Monitor progress
docker-compose -f docker-compose.claude.yml logs -f

# 4. Review changes
git status
git diff

# 5. When satisfied, stop the container
docker-compose -f docker-compose.claude.yml down

Notes

  • The container runs indefinitely until manually stopped
  • All project files are accessible to Claude (via volume mount)
  • Claude has full access to git, npm, and other development tools
  • API usage is billed to your Anthropic account based on Claude's activity

Reacties

Nog geen reacties