返回 CodeWhale
DOCKER.md
根目录 / docs / DOCKER.md
1 # Docker
2
3 > 阅读简体中文版:[zh_hans/DOCKER.md](zh_hans/DOCKER.md)。
4
5 Codewhale publishes a multi-arch Linux image to GitHub Container Registry
6 for each release.
7
8 Published multi-arch images live at `ghcr.io/hmbown/codewhale`.
9 To test the current `main` source, use [Building locally](#building-locally)
10 in a checkout of [`codewhale-hq/Codewhale`](https://github.com/codewhale-hq/Codewhale).
11
12 ```bash
13 docker pull ghcr.io/hmbown/codewhale:latest
14 ```
15
16 ## Quick start
17
18 Run the published image with a Docker-managed data volume:
19
20 ```bash
21 docker volume create codewhale-home
22
23 docker run --rm -it \
24 -e DEEPSEEK_API_KEY="$DEEPSEEK_API_KEY" \
25 -v codewhale-home:/home/codewhale/.codewhale \
26 -v "$PWD:/workspace" \
27 -w /workspace \
28 ghcr.io/hmbown/codewhale:latest
29 ```
30
31 Use a pinned release tag from [GitHub Releases](https://github.com/codewhale-hq/Codewhale/releases) for reproducible installs:
32
33 ```bash
34 docker run --rm -it \
35 -e DEEPSEEK_API_KEY="$DEEPSEEK_API_KEY" \
36 -v codewhale-home:/home/codewhale/.codewhale \
37 -v "$PWD:/workspace" \
38 -w /workspace \
39 ghcr.io/hmbown/codewhale:<release-tag>
40 ```
41
42 ## Default image contract
43
44 `ghcr.io/hmbown/codewhale:latest` and the semver tags are conservative runtime
45 images:
46
47 - the container runs as the non-root `codewhale` user with UID/GID `1000:1000`
48 - the image does not grant passwordless `sudo`
49 - the image is meant to run Codewhale against mounted workspaces, not to mutate
50 the base operating system at runtime
51 - user state belongs in a volume mounted at `/home/codewhale/.codewhale`
52
53 That default is intentional. Keep using it for the smallest trust boundary. If a
54 project needs `apt-get`, compiler toolchains, Node/Python package managers,
55 custom CA certificates, or other host-like setup inside Docker, build an
56 explicit toolbox image instead of changing the default image contract.
57
58 ## Opt-in toolbox/custom image
59
60 The repository includes an example
61 [`docs/examples/Dockerfile.toolbox`](examples/Dockerfile.toolbox) that extends
62 the official image with passwordless `sudo` and common development packages.
63 Build it with a pinned Codewhale tag when you want repeatable project
64 environments:
65
66 ```bash
67 docker build -f docs/examples/Dockerfile.toolbox \
68 --build-arg CODEWHALE_IMAGE=ghcr.io/hmbown/codewhale:<release-tag> \
69 --build-arg TOOLBOX_PACKAGES="git openssh-client curl build-essential pkg-config python3 python3-pip nodejs npm" \
70 -t codewhale-toolbox:my-project .
71 ```
72
73 Use `latest` only for throwaway testing. For shared projects, keep the
74 `CODEWHALE_IMAGE` value pinned and review package additions like any other
75 development-environment change.
76
77 Run the toolbox image with the same workspace and state mounts:
78
79 ```bash
80 docker volume create codewhale-my-project-home
81
82 docker run --rm -it \
83 -e DEEPSEEK_API_KEY="$DEEPSEEK_API_KEY" \
84 -v codewhale-my-project-home:/home/codewhale/.codewhale \
85 -v "$PWD:/workspace" \
86 -w /workspace \
87 codewhale-toolbox:my-project
88 ```
89
90 Inside this opt-in image, Codewhale can use commands such as
91 `sudo apt-get update` and `sudo apt-get install -y <package>`. For repeatable
92 containers, prefer baking those packages into the toolbox Dockerfile instead of
93 letting a long-lived container drift.
94
95 Do not bake API keys, SSH private keys, or other secrets into custom images.
96 Pass API keys at runtime and mount any SSH material deliberately, preferably
97 read-only and only for projects that need it.
98
99 ### Compose toolbox template
100
101 If you prefer a repeatable `docker compose` entry point, use
102 [`docs/examples/compose.toolbox.yml`](examples/compose.toolbox.yml). It builds
103 the toolbox image from [`docs/examples/Dockerfile.toolbox`](examples/Dockerfile.toolbox)
104 and keeps the project state volume explicit:
105
106 ```bash
107 CODEWHALE_IMAGE=ghcr.io/hmbown/codewhale:<release-tag> \
108 CODEWHALE_TOOLBOX_IMAGE=codewhale-toolbox:my-project \
109 CODEWHALE_HOME_VOLUME=codewhale-my-project-home \
110 CODEWHALE_WORKSPACE="$PWD" \
111 docker compose -f docs/examples/compose.toolbox.yml run --rm codewhale
112 ```
113
114 Use a different `CODEWHALE_TOOLBOX_IMAGE` and `CODEWHALE_HOME_VOLUME` for each
115 project that needs an independent toolchain or independent `.codewhale` state.
116 The Compose file also shows opt-in, read-only mounts for SSH material and local
117 CA certificates; keep those commented out unless the project needs them.
118
119 ## Multiple independent projects
120
121 Use one named state volume per project so sessions, config, skills, memory, and
122 the offline queue do not bleed across workspaces:
123
124 ```bash
125 project="$(basename "$PWD")"
126 image="codewhale-toolbox:${project}"
127 docker volume create "codewhale-${project}-home"
128
129 docker run --rm -it \
130 --name "codewhale-${project}" \
131 -e DEEPSEEK_API_KEY="$DEEPSEEK_API_KEY" \
132 -v "codewhale-${project}-home:/home/codewhale/.codewhale" \
133 -v "$PWD:/workspace" \
134 -w /workspace \
135 "$image"
136 ```
137
138 For projects with different toolchains, build different toolbox tags, for
139 example `codewhale-toolbox:frontend` and `codewhale-toolbox:backend`. The
140 separate launcher idea discussed in issue #2217 can build on this contract, but
141 it is intentionally outside the core Docker image.
142
143 ## Project bootstrap scripts
144
145 Codewhale does not automatically execute `.codewhale/setup.sh` or legacy
146 `.deepseek/setup.sh`. If you keep one of those files as a local project recipe,
147 run it explicitly. For shared team setup, prefer a committed project script or
148 the toolbox Dockerfile so the environment can be reviewed and rebuilt.
149
150 For example, to run a committed bootstrap script before starting Codewhale:
151
152 ```bash
153 docker run --rm -it \
154 -e DEEPSEEK_API_KEY="$DEEPSEEK_API_KEY" \
155 -v codewhale-my-project-home:/home/codewhale/.codewhale \
156 -v "$PWD:/workspace" \
157 -w /workspace \
158 --entrypoint bash \
159 codewhale-toolbox:my-project \
160 -lc './scripts/bootstrap-dev.sh && exec codewhale'
161 ```
162
163 Use the toolbox image for bootstrap scripts that need `sudo`. The default image
164 will not elevate privileges.
165
166 ## Custom CA certificates and proxies
167
168 For corporate proxies, dev-sidecar, or self-signed internal services, prefer
169 baking trusted CA certificates into a custom toolbox image:
170
171 ```dockerfile
172 USER root
173 COPY docker/certs/*.crt /usr/local/share/ca-certificates/
174 RUN update-ca-certificates
175 USER codewhale
176 ```
177
178 All files copied into `/usr/local/share/ca-certificates/` must use the `.crt`
179 extension. Keep private CA material out of public images.
180
181 For a local-only run, mount certificates read-only and update the trust store at
182 container start:
183
184 ```bash
185 docker run --rm -it \
186 -e DEEPSEEK_API_KEY="$DEEPSEEK_API_KEY" \
187 -v codewhale-my-project-home:/home/codewhale/.codewhale \
188 -v "$PWD:/workspace" \
189 -v "$PWD/docker/certs:/usr/local/share/ca-certificates/local:ro" \
190 -w /workspace \
191 --entrypoint bash \
192 codewhale-toolbox:my-project \
193 -lc 'sudo update-ca-certificates && exec codewhale'
194 ```
195
196 This CA workflow requires the opt-in toolbox image because the default image
197 does not include passwordless `sudo`.
198
199 ## Local build
200
201 Build the image locally from a checkout:
202
203 ```bash
204 docker build -t codewhale .
205 ```
206
207 Then run it with the same Docker-managed data volume:
208
209 ```bash
210 docker run --rm -it \
211 -e DEEPSEEK_API_KEY="$DEEPSEEK_API_KEY" \
212 -v codewhale-home:/home/codewhale/.codewhale \
213 -v "$PWD:/workspace" \
214 -w /workspace \
215 codewhale
216 ```
217
218 Docker Hub publishing is not configured; GHCR is the supported prebuilt image
219 registry.
220
221 ## Environment variables
222
223 | Variable | Required | Description |
224 |-----------------------|----------|--------------------------------------------------|
225 | `DEEPSEEK_API_KEY` | yes | DeepSeek API key |
226 | `DEEPSEEK_BASE_URL` | no | Custom API base URL (e.g. `https://api.deepseek.com`) |
227 | `DEEPSEEK_NO_COLOR` | no | Set to `1` to disable terminal colour output |
228
229 ## Volumes
230
231 Mount `/home/codewhale/.codewhale` to persist sessions, config, skills, memory,
232 and the offline queue across container restarts. The image also keeps
233 `/home/codewhale/.deepseek` available for legacy compatibility. A
234 Docker-managed named volume is the safest default because Docker creates it with
235 ownership the container can write:
236
237 ```bash
238 -v codewhale-home:/home/codewhale/.codewhale
239 ```
240
241 Without this mount the container starts fresh each time.
242
243 If you bind-mount an existing host directory instead, the image runs as the
244 non-root `codewhale` user with UID/GID `1000:1000`. The mounted directory must be
245 writable by that user, or startup can fail while creating runtime directories
246 under `.codewhale/tasks`. On Linux hosts, either use the named volume above or
247 prepare the bind mount explicitly:
248
249 ```bash
250 mkdir -p ~/.codewhale
251 sudo chown -R 1000:1000 ~/.codewhale
252
253 docker run --rm -it \
254 -e DEEPSEEK_API_KEY="$DEEPSEEK_API_KEY" \
255 -v ~/.codewhale:/home/codewhale/.codewhale \
256 ghcr.io/hmbown/codewhale:latest
257 ```
258
259 That `chown` changes ownership of the host `~/.codewhale` directory. Skip it if
260 you do not want the container UID to own your local config, and use a named
261 volume instead.
262
263 ## Non-interactive / pipeline usage
264
265 When stdin is not a TTY, `codewhale` drops to the dispatcher's one-shot mode
266 (`codewhale -c "…"`). Pipe a prompt on stdin:
267
268 ```bash
269 echo "Explain the Cargo.toml in structured English." | \
270 docker run --rm -i -e DEEPSEEK_API_KEY ghcr.io/hmbown/codewhale:latest
271 ```
272
273 ## Building locally
274
275 ```bash
276 # Single platform (your host architecture)
277 docker build -t codewhale .
278
279 # Multi-platform (requires a builder with emulation)
280 docker buildx create --use
281 docker buildx build --platform linux/amd64,linux/arm64 -t codewhale .
282 ```
283
284 ## Devcontainer
285
286 The repository includes a [`.devcontainer/devcontainer.json`](../.devcontainer/devcontainer.json)
287 configuration for VS Code / GitHub Codespaces. It builds a dedicated development
288 image with the Rust toolchain, Git, `pkg-config`, and the DBus development headers
289 required by the workspace. The first open runs `cargo build --locked` and installs
290 rust-analyzer and the other editor extensions.
291
292 The source checkout remains mounted from the host. Codewhale state and Cargo build
293 artifacts use Docker named volumes instead, so the configuration works when VS Code
294 cannot provide a POSIX-style `HOME` variable (notably on Windows), and builds do not
295 write thousands of small files through a Windows bind mount. Rebuild the container
296 after changing the Dev Container configuration.
297
298 ## Release status
299
300 Docker image publishing is part of the release gate. The image is published to
301 GHCR for `linux/amd64` and `linux/arm64` with semver tags plus `latest`.
302
302 lines MARKDOWN