Skip to content

About

Docker builds for various agent containers

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Claude Docker

A comprehensive Docker container for running Claude Code with full permissions, GitHub integration, and Jira access.

Table of Contents

Features

  • 🤖 Claude Code Integration: Runs Claude Code with --dangerously-skip-permissions flag for full functionality
  • 🔑 API Key Management: Secure handling of Anthropic API key via environment variables
  • 📁 Volume Mounting: Access to local files through Docker volume mounting
  • 🔐 GitHub Integration: SSH key support for GitHub operations
  • 🎫 Jira Integration: API key support for Jira ticket access
  • 🏗️ Automated Builds: GitHub Actions workflow for building and publishing to GitHub Container Registry
  • 🐳 Multi-Architecture: Supports both AMD64 and ARM64 architectures
  • 📦 Extensible: Support for installing additional packages at runtime

Architecture

Design Overview

The Claude Docker container is designed with the following principles:

  1. Security First: All sensitive credentials are passed as environment variables
  2. Flexibility: Supports multiple integration options (GitHub, Jira) that can be enabled/disabled
  3. Ease of Use: Simple command-line interface with sensible defaults
  4. CI/CD Ready: Automated builds and publishing to GitHub Container Registry

Container Structure

/home/claude/
├── .ssh/                 # SSH configuration (generated at runtime)
├── .config/              # Application configurations
│   └── jira/            # Jira configuration (generated at runtime)
├── workspace/           # Mounted volume for local files
└── entrypoint.sh        # Container initialization script

Build Process

  1. Base image: Ubuntu 22.04 for maximum compatibility
  2. Installs required dependencies (Node.js, Git, SSH client, etc.)
  3. Installs Claude Code globally via npm
  4. Creates non-root user for security
  5. Sets up entrypoint script for runtime configuration

Prerequisites

Required Accounts and Keys

1. Anthropic API Key

  1. Sign up at Anthropic Console
  2. Navigate to API Keys section
  3. Create a new API key
  4. Save the key securely - you'll need it as ANTHROPIC_API_KEY

2. GitHub SSH Key (Optional)

Generate a new SSH key for GitHub access:

# Generate SSH key
ssh-keygen -t ed25519 -C "your_email@example.com" -f claude_github_key

# Display the public key to add to GitHub
cat claude_github_key.pub

# Save the private key content for GITHUB_SSH_KEY
cat claude_github_key

Add the public key to GitHub:

  1. Go to GitHub Settings → SSH and GPG keys
  2. Click "New SSH key"
  3. Paste the public key content
  4. Save

3. Jira/Atlassian API Token (Optional)

  1. Log in to Atlassian account
  2. Go to Security → API tokens
  3. Create a new API token
  4. Save the token securely - you'll need it as JIRA_API_TOKEN

Quick Start

Using Pre-built Image

# Pull the latest image
docker pull ghcr.io/yourusername/claude-docker:latest

# Run with minimal configuration
docker run -it --rm \
  -e ANTHROPIC_API_KEY="your_api_key_here" \
  -v $(pwd):/home/claude/workspace \
  ghcr.io/yourusername/claude-docker:latest

# Run with full configuration
docker run -it --rm \
  -e ANTHROPIC_API_KEY="your_api_key_here" \
  -e GITHUB_USERNAME="your_github_username" \
  -e GITHUB_SSH_KEY="$(cat ~/.ssh/claude_github_key)" \
  -e GITHUB_EMAIL="your_email@example.com" \
  -e JIRA_API_TOKEN="your_jira_token" \
  -e JIRA_USER_EMAIL="your_jira_email@example.com" \
  -e JIRA_INSTANCE_URL="https://your-domain.atlassian.net" \
  -v $(pwd):/home/claude/workspace \
  ghcr.io/yourusername/claude-docker:latest

Building Locally

# Clone the repository
git clone https://github.com/yourusername/claude-docker.git
cd claude-docker

# Build the image
docker build -t claude-docker .

# Run the container
docker run -it --rm \
  -e ANTHROPIC_API_KEY="your_api_key_here" \
  -v $(pwd):/home/claude/workspace \
  claude-docker

Configuration

Environment Variables

Variable Required Description
ANTHROPIC_API_KEY Yes Your Anthropic API key for Claude
GITHUB_USERNAME No GitHub username for git commits
GITHUB_EMAIL No Email for git commits
GITHUB_SSH_KEY No Private SSH key content for GitHub
JIRA_API_TOKEN No Jira API token
JIRA_USER_EMAIL No Email associated with Jira account
JIRA_INSTANCE_URL No Jira instance URL (e.g., https://company.atlassian.net)
EXTRA_PACKAGES No Space-separated list of apt packages to install
NPM_PACKAGES No Space-separated list of npm packages to install globally

Docker Compose

For easier local development, use the provided docker-compose.yml:

# Copy and edit the environment file
cp .env.example .env
# Edit .env with your credentials

# Start the container
docker-compose up

# Run in detached mode
docker-compose up -d

# Stop the container
docker-compose down

Usage

Helper Scripts

scripts/run-claude.sh

Convenience script for running Claude Docker:

# Basic usage
./scripts/run-claude.sh

# With GitHub integration
./scripts/run-claude.sh --github

# With Jira integration
./scripts/run-claude.sh --jira

# With custom workspace
./scripts/run-claude.sh --workspace /path/to/project

scripts/setup.sh

Interactive setup script for first-time configuration:

# Run setup wizard
./scripts/setup.sh

# This will:
# - Check for required dependencies
# - Help you obtain API keys
# - Generate SSH keys if needed
# - Create .env file
# - Test the configuration

Command Line Alias

Add to your shell configuration (.bashrc, .zshrc, etc.):

# Claude Docker alias
alias claude='docker run -it --rm \
  -e ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY}" \
  -v $(pwd):/home/claude/workspace \
  ghcr.io/yourusername/claude-docker:latest'

# Claude with GitHub
alias claude-gh='docker run -it --rm \
  -e ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY}" \
  -e GITHUB_USERNAME="${GITHUB_USERNAME}" \
  -e GITHUB_SSH_KEY="$(cat ~/.ssh/claude_github_key)" \
  -e GITHUB_EMAIL="${GITHUB_EMAIL}" \
  -v $(pwd):/home/claude/workspace \
  ghcr.io/yourusername/claude-docker:latest'

Development

Project Structure

claude-docker/
├── Dockerfile              # Main container definition
├── entrypoint.sh          # Runtime initialization script
├── docker-compose.yml     # Docker Compose configuration
├── .env.example          # Example environment variables
├── .github/
│   └── workflows/
│       └── build-and-publish.yml  # CI/CD pipeline
├── scripts/
│   ├── run-claude.sh     # Convenience runner script
│   ├── setup.sh          # Interactive setup wizard
│   └── test.sh           # Testing script
└── README.md             # This file

Testing

Run the test suite:

# Run all tests
./scripts/test.sh

# Test specific functionality
./scripts/test.sh --github
./scripts/test.sh --jira
./scripts/test.sh --build

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

CI/CD

GitHub Actions Workflow

The repository includes a GitHub Actions workflow that:

  1. Triggers on:

    • Push to main/master branches
    • Version tags (v*)
    • Pull requests
    • Manual workflow dispatch
  2. Build Process:

    • Sets up Docker Buildx for multi-platform builds
    • Logs into GitHub Container Registry
    • Builds for AMD64 and ARM64 architectures
    • Pushes to ghcr.io with appropriate tags
    • Generates build attestation for security

Setting Up CI/CD

  1. The GitHub Actions workflow uses the built-in GITHUB_TOKEN, so no additional secrets are needed
  2. Ensure "Packages" write permission is enabled in repository settings
  3. Images will be published to ghcr.io/yourusername/repository-name

Image Tags

  • latest: Latest build from main branch
  • main or master: Branch-specific builds
  • v1.0.0: Version tags
  • pr-123: Pull request builds
  • main-abc1234: Commit-specific builds

Security Considerations

Best Practices

  1. Never commit credentials: All sensitive data should be passed as environment variables
  2. Use secrets management: Consider using Docker secrets or external secret management tools
  3. Rotate keys regularly: Implement a key rotation policy for all API keys and tokens
  4. Limit permissions: The container runs as a non-root user by default
  5. Network isolation: Consider running in a Docker network with limited external access

SSH Key Management

  • SSH keys are stored temporarily in the container and removed when the container stops
  • Consider using short-lived SSH keys or SSH certificates
  • Use separate keys for different environments (dev, staging, production)

API Key Security

  • Store API keys in a secure password manager
  • Use environment-specific keys when possible
  • Monitor API key usage in respective dashboards
  • Implement rate limiting where applicable

Troubleshooting

Common Issues

1. ANTHROPIC_API_KEY not working

# Verify the key is set correctly
docker run -it --rm \
  -e ANTHROPIC_API_KEY="your_key" \
  claude-docker \
  bash -c 'echo $ANTHROPIC_API_KEY'

# Test API connectivity
docker run -it --rm \
  -e ANTHROPIC_API_KEY="your_key" \
  claude-docker \
  bash -c 'curl -H "x-api-key: $ANTHROPIC_API_KEY" https://api.anthropic.com/v1/messages'

2. GitHub SSH not working

# Test SSH connectivity
docker run -it --rm \
  -e GITHUB_SSH_KEY="$(cat ~/.ssh/claude_github_key)" \
  claude-docker \
  bash -c 'ssh -T git@github.com'

# Debug SSH issues
docker run -it --rm \
  -e GITHUB_SSH_KEY="$(cat ~/.ssh/claude_github_key)" \
  claude-docker \
  bash -c 'ssh -vvv git@github.com'

3. Volume mounting issues

# Check volume permissions
ls -la $(pwd)

# Run with explicit permissions
docker run -it --rm \
  --user $(id -u):$(id -g) \
  -v $(pwd):/home/claude/workspace \
  claude-docker

4. Container won't start

# Check container logs
docker logs container_id

# Run with debug output
docker run -it --rm \
  -e DEBUG=true \
  -e ANTHROPIC_API_KEY="your_key" \
  claude-docker

Getting Help

  1. Check the Issues page
  2. Review the Discussions
  3. Create a new issue with:
    • Docker version
    • Operating system
    • Complete error messages
    • Steps to reproduce

License

MIT License - see LICENSE file for details

Acknowledgments

  • Anthropic for Claude and Claude Code
  • Docker for containerization technology
  • Community contributors and testers

About

Docker builds for various agent containers

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages