-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathContainerfile
More file actions
235 lines (202 loc) · 10 KB
/
Containerfile
File metadata and controls
235 lines (202 loc) · 10 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# localdev - Lightweight development container (DEFAULT)
# Optimized for fast startup - no Java, no Atlassian CLI
# For full container with Java and Atlassian CLI, see Dockerfile.full
# Multi-arch: supports linux/amd64 and linux/arm64
FROM debian:bookworm-slim
# OCI annotations for image metadata
LABEL org.opencontainers.image.title="localdev" \
org.opencontainers.image.description="Lightweight isolated development container for Claude Code and AI assistants with Node.js LTS, Go, and essential tools" \
org.opencontainers.image.url="https://github.com/gherlein/localdev" \
org.opencontainers.image.source="https://github.com/gherlein/localdev" \
org.opencontainers.image.documentation="https://github.com/gherlein/localdev/blob/main/README.md" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.vendor="Greg Herlein" \
org.opencontainers.image.authors="Greg Herlein"
# Install dependencies
RUN apt-get update && apt-get install -y \
sudo \
curl \
git \
unzip \
build-essential \
cmake \
squashfs-tools \
zip \
file \
xxd \
ffmpeg \
qpdf \
imagemagick \
libpcap-dev \
jq \
gosu \
python3 \
python3-pip \
tree \
tmux \
mg \
rsync \
zoxide \
keychain \
direnv \
ca-certificates \
zstd && rm -rf /var/lib/apt/lists/*
# Install Node.js LTS only using nvm
ENV NVM_DIR=/usr/local/nvm
RUN mkdir -p $NVM_DIR && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash && \
. $NVM_DIR/nvm.sh && \
nvm install --lts && \
nvm alias default node && \
nvm use default
# Add nvm to PATH - source nvm in subsequent RUN commands
ENV NODE_PATH="$NVM_DIR/versions/node"
SHELL ["/bin/bash", "-c"]
# Set PATH to include the default Node.js version installed by nvm
# Also create a symlink for consistent path across node version updates
RUN . $NVM_DIR/nvm.sh && \
ln -s "$NVM_DIR/versions/node/$(nvm version default)" "$NVM_DIR/default" && \
echo "export PATH=\"$NVM_DIR/default/bin:\$PATH\"" >> /etc/environment
# Add node to PATH at container level (required for scripts like clauded)
ENV PATH="$NVM_DIR/default/bin:${PATH}"
# Install Ollama
RUN curl -fsSL https://ollama.com/install.sh | sh
# Install Podman
RUN apt-get update && apt-get install -y \
podman \
uidmap \
fuse-overlayfs \
slirp4netns && \
rm -rf /var/lib/apt/lists/*
# Configure Podman for rootless operation
RUN mkdir -p /etc/containers && \
echo '[containers]' > /etc/containers/containers.conf && \
echo 'netns="host"' >> /etc/containers/containers.conf && \
echo 'userns="host"' >> /etc/containers/containers.conf && \
echo 'ipcns="host"' >> /etc/containers/containers.conf && \
echo 'utsns="host"' >> /etc/containers/containers.conf && \
echo 'cgroupns="host"' >> /etc/containers/containers.conf && \
echo 'cgroups="disabled"' >> /etc/containers/containers.conf && \
echo 'devices="/dev/null"' >> /etc/containers/containers.conf && \
echo '[engine]' >> /etc/containers/containers.conf && \
echo 'cgroup_manager="cgroupfs"' >> /etc/containers/containers.conf && \
echo 'events_logger="file"' >> /etc/containers/containers.conf && \
echo 'runtime="crun"' >> /etc/containers/containers.conf
# Install GitHub CLI
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && \
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && \
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null && \
apt-get update && \
apt-get install -y gh && \
rm -rf /var/lib/apt/lists/*
# Install Go
ARG GO_VERSION=1.25.0
ARG TARGETARCH
RUN echo "TARGETARCH: ${TARGETARCH}" && \
GOARCH="${TARGETARCH}" && \
if [ "${TARGETARCH}" = "amd64" ]; then GOARCH=amd64; fi && \
if [ "${TARGETARCH}" = "arm64" ]; then GOARCH=arm64; fi && \
echo "GOARCH: ${GOARCH}" && \
curl -fsSL https://dl.google.com/go/go${GO_VERSION}.linux-${GOARCH}.tar.gz | tar --no-same-permissions --no-same-owner -xzC /usr/local
# Set Go environment variables
ENV GOROOT=/usr/local/go
ENV GOPATH=/home/developer/go
ENV PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}"
# Install TinyGo
ARG TINYGO_VERSION=0.40.1
RUN TINYGO_ARCH="${TARGETARCH}" && \
if [ "${TARGETARCH}" = "amd64" ]; then TINYGO_ARCH=amd64; fi && \
if [ "${TARGETARCH}" = "arm64" ]; then TINYGO_ARCH=arm64; fi && \
echo "TINYGO_ARCH: ${TINYGO_ARCH}" && \
curl -fsSL "https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_VERSION}/tinygo_${TINYGO_VERSION}_${TINYGO_ARCH}.deb" -o /tmp/tinygo.deb && \
dpkg -i /tmp/tinygo.deb && \
rm /tmp/tinygo.deb
# Create a new user with UID/GID 1000 to match host user
RUN (groupadd -g 1000 developer 2>/dev/null || groupmod -n developer $(getent group 1000 | cut -d: -f1)) && \
(useradd -m -u 1000 -g 1000 -s /bin/bash developer 2>/dev/null || \
usermod -l developer -d /home/developer -m $(getent passwd 1000 | cut -d: -f1) 2>/dev/null || true) && \
echo 'developer ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
# Fix permissions for developer user
RUN mkdir -p /home/developer/go/{bin,src,pkg} && \
chown -R 1000:1000 /home/developer
# Install essential npm tools only (Claude Code installed later as developer user)
RUN . $NVM_DIR/nvm.sh && \
NODE_OPTIONS="--max-old-space-size=4096" npm install -g \
typescript \
ts-node \
pnpm \
eslint \
prettier \
@mariozechner/pi-coding-agent && \
npm cache clean --force
# Setup lazy-load nvm in bash for all users (loads on first use)
RUN echo 'export NVM_DIR=/usr/local/nvm' >> /etc/bash.bashrc && \
echo '# Lazy-load nvm for faster shell startup' >> /etc/bash.bashrc && \
echo 'nvm() { unset -f nvm node npm npx; . "$NVM_DIR/nvm.sh"; nvm "$@"; }' >> /etc/bash.bashrc && \
echo 'node() { unset -f nvm node npm npx; . "$NVM_DIR/nvm.sh"; node "$@"; }' >> /etc/bash.bashrc && \
echo 'npm() { unset -f nvm node npm npx; . "$NVM_DIR/nvm.sh"; npm "$@"; }' >> /etc/bash.bashrc && \
echo 'npx() { unset -f nvm node npm npx; . "$NVM_DIR/nvm.sh"; npx "$@"; }' >> /etc/bash.bashrc && \
echo '# Add default node to PATH for non-interactive use' >> /etc/bash.bashrc && \
echo 'export PATH="$NVM_DIR/versions/node/$(cat $NVM_DIR/alias/default 2>/dev/null || echo "v22")/bin:$PATH" 2>/dev/null || true' >> /etc/bash.bashrc && \
echo '# Add user npm global binaries to PATH' >> /etc/bash.bashrc && \
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> /etc/bash.bashrc && \
echo '# Alias emacs to mg' >> /etc/bash.bashrc && \
echo 'alias emacs=mg' >> /etc/bash.bashrc && \
echo '# Claude dangerous mode alias (backup - also in dotfiles)' >> /etc/bash.bashrc && \
echo 'alias clauded="claude --dangerously-skip-permissions"' >> /etc/bash.bashrc
# Install stow for dotfiles management
RUN apt-get update && apt-get install -y stow && rm -rf /var/lib/apt/lists/*
# Stow dotfiles and source user bash config at shell startup
RUN echo '# Stow dotfiles from /external/dotfiles if present (bash package handled separately)' >> /etc/bash.bashrc && \
echo 'if [[ -d /external/dotfiles ]]; then' >> /etc/bash.bashrc && \
echo ' for _dotpkg_dir in /external/dotfiles/*/; do' >> /etc/bash.bashrc && \
echo ' _dotpkg=$(basename "$_dotpkg_dir")' >> /etc/bash.bashrc && \
echo ' [[ "$_dotpkg" == "bash" ]] && continue' >> /etc/bash.bashrc && \
echo ' stow --no-folding --dir=/external/dotfiles --target="$HOME" "$_dotpkg" 2>/dev/null || true' >> /etc/bash.bashrc && \
echo ' done' >> /etc/bash.bashrc && \
echo ' unset _dotpkg_dir _dotpkg' >> /etc/bash.bashrc && \
echo ' [[ -f /external/dotfiles/bash/.bashrc ]] && source /external/dotfiles/bash/.bashrc' >> /etc/bash.bashrc && \
echo ' [[ -f /external/dotfiles/bash/.bash_profile ]] && source /external/dotfiles/bash/.bash_profile' >> /etc/bash.bashrc && \
echo 'fi' >> /etc/bash.bashrc && \
echo '# Keep ~/bin available but at the end of PATH so container-installed tools' >> /etc/bash.bashrc && \
echo '# take precedence over host-mounted binaries built for a different arch.' >> /etc/bash.bashrc && \
echo 'export PATH="$(printf "%s" "$PATH" | tr ":" "\n" | grep -v "^/home/developer/bin$" | tr "\n" ":" | sed "s/:$//"):/home/developer/bin"' >> /etc/bash.bashrc && \
echo '# Return to workspace after dotfiles may have changed directory' >> /etc/bash.bashrc && \
echo '[[ -n "$WORKSPACE" && -d "$WORKSPACE" ]] && cd "$WORKSPACE"' >> /etc/bash.bashrc
WORKDIR /home/developer
# Install udev and USB libraries for device access
RUN apt-get update && apt-get install -y \
udev \
libusb-1.0-0 \
libusb-1.0-0-dev \
usbutils \
&& rm -rf /var/lib/apt/lists/*
# Switch to developer user
USER developer
# Update PATH to include user-local npm binaries
ENV PATH="/home/developer/.npm-global/bin:${PATH}"
# Configure npm prefix for developer user
RUN mkdir -p "$HOME/.npm-global" && \
npm config set prefix "$HOME/.npm-global"
# Install Claude Code using native installer
RUN curl -fsSL https://claude.ai/install.sh | bash
# install uv with retry logic
RUN for i in 1 2 3; do \
curl -LsSf https://astral.sh/uv/install.sh | sh && break || \
(echo "Attempt $i failed, retrying..." && sleep 5); \
done
# Add uv to PATH
ENV PATH="/home/developer/.local/bin:${PATH}"
# Install essential Go tools only
RUN go install golang.org/x/tools/cmd/goimports@latest && \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest && \
go install github.com/go-delve/delve/cmd/dlv@latest
# Switch back to root so the entrypoint can remap UID/GID at runtime
USER root
# Copy launcher scripts into container for easy extraction
COPY localdev localdevnet localdevpull /opt/localdev/bin/
RUN chmod +x /opt/localdev/bin/*
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/bin/bash"]