-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
66 lines (56 loc) · 2.59 KB
/
Copy pathDockerfile
File metadata and controls
66 lines (56 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# claude-code-docker: run Anthropic's Claude Code CLI in a container.
#
# docker build -t claude-code-docker .
# docker build --build-arg CLAUDE_CODE_VERSION=2.1.227 -t claude-code-docker . # pin another release
#
# Design notes:
# - debian:bookworm-slim + the official native installer, which ships a
# self-contained binary: no Node.js at runtime, so this image ships none.
# - Runs as a non-root user. This is not a style choice: claude refuses
# --dangerously-skip-permissions when running as root.
# - CLAUDE_CONFIG_DIR keeps ALL state (OAuth credentials, settings, history) under
# /home/claude/.claude, so one volume mount survives container rebuilds. Without
# it, account state in ~/.claude.json would live outside the volume.
FROM debian:bookworm-slim
ARG CLAUDE_CODE_VERSION=2.1.235
# Match your host UID/GID so files created in the bind-mounted /workspace are yours
# (Linux hosts; Docker Desktop on macOS/Windows maps ownership automatically).
ARG UID=1000
ARG GID=1000
# git, curl, ripgrep, procps: what Claude Code actually uses day to day.
# iptables, ipset, dnsutils, jq, sudo: only for the optional egress firewall
# (init-firewall.sh), inert unless you start the container with FIREWALL=1.
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
ripgrep \
procps \
iptables \
ipset \
dnsutils \
jq \
sudo \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd -g "$GID" claude \
&& useradd -m -u "$UID" -g "$GID" -s /bin/bash claude
COPY init-firewall.sh entrypoint.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/init-firewall.sh /usr/local/bin/entrypoint.sh \
# ipset needs the legacy iptables backend inside containers.
&& update-alternatives --set iptables /usr/sbin/iptables-legacy \
&& update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy \
# The firewall needs root for iptables; this is the ONLY thing claude may sudo.
# SETENV lets the entrypoint pass FIREWALL_ALLOW_DOMAINS through.
&& echo "claude ALL=(root) NOPASSWD:SETENV: /usr/local/bin/init-firewall.sh" > /etc/sudoers.d/claude-firewall \
&& chmod 440 /etc/sudoers.d/claude-firewall
USER claude
WORKDIR /home/claude
ENV PATH="/home/claude/.local/bin:${PATH}" \
CLAUDE_CONFIG_DIR=/home/claude/.claude \
# Containers should be rebuilt deliberately, not self-mutate mid-session.
DISABLE_AUTOUPDATER=1
# Official installer, pinned. The binary lands in ~/.local/bin/claude.
RUN curl -fsSL https://claude.ai/install.sh | bash -s "$CLAUDE_CODE_VERSION"
WORKDIR /workspace
ENTRYPOINT ["entrypoint.sh"]
CMD ["claude"]