Last active
June 16, 2025 22:58
-
-
Save GeorgeLyon/5bfb6385db6a2bb511478d3d48f4d3fc to your computer and use it in GitHub Desktop.
Claude Code in Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
CONFIG_ROOT="$HOME/.claude-code" | |
mkdir -p "$CONFIG_ROOT/claude" | |
touch "$CONFIG_ROOT/claude.json" | |
docker run \ | |
--rm -ti \ | |
--mount type=volume,source=claude-code-npm,target=/root/.npm \ | |
--mount type=volume,source=claude-code-node-modules,target=/usr/local/lib/node_modules \ | |
--mount type=bind,source="$CONFIG_ROOT/claude",target=/root/.claude \ | |
--mount type=bind,source="$CONFIG_ROOT/claude.json",target=/root/.claude.json \ | |
--mount type=bind,source="$PWD",target=/workspace \ | |
-w /workspace \ | |
"$(DOCKER_BUILDKIT=1 docker build -q -f- . <<'DOCKERFILE_EOF' | |
# syntax=docker/dockerfile:1.3-labs | |
FROM swift:latest | |
# Install Claude Code | |
RUN \ | |
DEBIAN_FRONTEND=noninteractive \ | |
apt-get update && \ | |
apt-get install -y \ | |
ripgrep \ | |
nodejs \ | |
npm \ | |
wget | |
## Install gh cli | |
RUN \ | |
mkdir -p -m 755 /etc/apt/keyrings \ | |
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \ | |
&& cat $out | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ | |
&& chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ | |
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \ | |
DEBIAN_FRONTEND=noninteractive \ | |
apt-get update && \ | |
apt-get install -y \ | |
gh | |
RUN \ | |
npm install -g @anthropic-ai/claude-code | |
COPY <<'EOF' /root/entrypoint.sh | |
#!/bin/bash | |
MARKER_FILE="/root/.npm/.claude-code-installed" | |
if [[ ! -f "$MARKER_FILE" ]]; then | |
npm install -g @anthropic-ai/claude-code | |
touch "$MARKER_FILE" | |
fi | |
/usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js "$@" | |
EOF | |
RUN chmod +x /root/entrypoint.sh | |
ENTRYPOINT ["/root/entrypoint.sh"] | |
DOCKERFILE_EOF | |
)" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment