Implement authentication persistence for Claude Docker

- Add persistent volume mount for Claude home directory (~/.claude)
- Create non-root user in Docker container for better security
- Mount host ~/.claude-docker/claude-home to container ~/.claude
- Update install script to create claude-home directory
- Check for existing credentials on startup
- Authentication tokens now persist across container restarts
This commit is contained in:
Vishal Jain
2025-06-12 14:09:10 +01:00
parent c99bc9c561
commit dcc936dc10
5 changed files with 87 additions and 17 deletions

View File

@@ -38,12 +38,16 @@ if ! docker images | grep -q "claude-docker"; then
docker build -t claude-docker:latest "$PROJECT_ROOT"
fi
# Ensure the claude-home directory exists
mkdir -p "$HOME/.claude-docker/claude-home"
# Run Claude Code in Docker
echo "Starting Claude Code in Docker..."
docker run -it --rm \
-v "$CURRENT_DIR:/workspace" \
-v "$ENV_FILE:/app/.env:ro" \
-v "$HOME/.claude-docker/config:/app/.claude:rw" \
-v "$HOME/.claude-docker/claude-home:/home/claude-user/.claude:rw" \
--workdir /workspace \
--name claude-docker-session \
claude-docker:latest "$@"

View File

@@ -5,8 +5,9 @@
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Create config directory
# Create config directory and claude persistence directory
mkdir -p "$HOME/.claude-docker/config"
mkdir -p "$HOME/.claude-docker/claude-home"
# Copy example env file if doesn't exist
if [ ! -f "$HOME/.claude-docker/.env" ]; then

View File

@@ -12,6 +12,14 @@ fi
# Configure Claude Code to use the MCP server
export CLAUDE_MCP_CONFIG=/app/config/mcp-config.json
# Check for existing authentication
if [ -f "$HOME/.claude/.credentials.json" ]; then
echo "Found existing Claude authentication"
else
echo "No existing authentication found - you will need to log in"
echo "Your login will be saved for future sessions"
fi
# Start Claude Code with permissions bypass
echo "Starting Claude Code..."
if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_API_KEY" ]; then
@@ -19,5 +27,4 @@ if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_API_KEY" ]; then
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 "$@"