Repository navigation
06 Devcontainer
croft can route terminal sessions and host-targeted recipes into a
project's devcontainer instead of running
them on the host. The feature is opt-in: croft ignores
devcontainer.json until you flip it on.
[devcontainer]
enabled = true
# Optional: override auto-detect.
# path = ".devcontainer/devcontainer.json"When enabled, croft auto-detects .devcontainer/devcontainer.json
first, then .devcontainer.json. Use path to point at a custom
location (e.g. when you keep multiple variants in one repo).
| Path | Off (default) | On |
|---|---|---|
TUI n / new shell |
$SHELL on host |
docker exec into devcontainer |
Recipe without in =
|
host fork | runs inside devcontainer |
Recipe with in = "<svc>"
|
unchanged | unchanged |
croft shell |
(no command) | enters devcontainer |
croft shell --service app |
(no command) | enters compose service app (devcontainer toggle irrelevant) |
Existing routing for in = "<service>" is unaffected. Devcontainer
and compose services are different targets: the compose backend keeps
managing [services.app], and the devcontainer keeps being the
workspace shell. They coexist.
croft parses a subset of the spec — enough for the most common "isolated workspace image" pattern:
name-
imageorbuild: { dockerfile, context, args } -
workspaceFolder(default:/workspaces/<project-root-basename>) -
runArgs(passed through todocker run; privilege-escalating entries log a warning) -
containerEnv(baked in atdocker run) -
remoteEnv(merged on top of croft recipe env atdocker exec) remoteUser
Comments and trailing commas in the JSON are accepted (the file format is JSONC).
-
dockerComposeFile— rejected with an error. Use croft's existingruntime.backend = "compose"instead, and route recipes to your dev service within = "<service>". The two approaches solve the same problem; reimplementing dockerComposeFile would just duplicate the compose backend. -
features,postCreateCommand,onCreateCommand,updateContentCommand,forwardPorts,mounts, customworkspaceMountstrings — ignored.
croft owns the container's lifecycle: there's no separate "up" step to run.
-
First use (TUI
npress, recipe run,croft shell):- For
buildmode, build the image and tag itcroft-devcontainer-<project>:<sha>, where<sha>is a hash of the dockerfile + build args. Skipped if the tag already exists. -
docker run -dthe container with--name croft-devcontainer-<project>[-<worktree>], the workspace bind-mounted toworkspaceFolder, and the devcontainer'scontainerEnv+remoteUserapplied. Keep-alive command: a portable infinitesleeploop.
- For
-
Subsequent uses:
docker exec -it <name> .... If the container is stopped, croftdocker starts it first.
To rebuild after editing the Dockerfile or build args, change a build input — the hash changes, croft detects the missing tag, and rebuilds. To rebuild without changing inputs:
docker rm -f croft-devcontainer-<project>
docker image rm croft-devcontainer-<project>:<tag>Each git worktree gets its own devcontainer.
- Container name:
croft-devcontainer-<project-slug>-<worktree-slug> - Bind mount: the worktree's own root →
workspaceFolder - Labels:
croft.shcontainer.root=<absolute path>,croft.shcontainer.worktree=<slug>
This mirrors WorktreesConfig::isolate_compose for the compose
backend. Two worktrees of the same project can be running
side-by-side, each with an independent container.
croft doctor reports the active devcontainer setup (config path,
dockerfile presence, container name → image → workspace folder) and
warns on privilege-escalating runArgs. The check is skipped
entirely when [devcontainer] enabled = false.
- Container Backends for the existing compose / podman / docker routing — devcontainer is orthogonal.
- Worktrees for slug derivation and isolation.
croft is dual-licensed under MIT or Apache 2.0. Source: github.com/nsrosenqvist/croft. Back to Home.