nodecode-docker
Docker, read-only: the containers, their logs, a container inspected with its secrets taken out, live resource use, the local images and the compose projects, through the docker CLI. Written for Nodecode from the Docker CLI reference.
Get it
Tell the agent "add the docker cell", or run nodecode add nc://docker.
Set it up
Install the Docker CLI so docker is on PATH, and let the user Nodecode runs as read the daemon (the docker group), or point the cell at another daemon. See config.example.jsonc:
| Key | Default | What it does |
|---|---|---|
command |
["docker"] |
The argv prefix that runs the CLI: an install on PATH, or its absolute path. |
context |
"" |
A docker context to read instead of the current one, passed as --context. |
host |
"" |
A daemon address set as DOCKER_HOST for every run (unix://, ssh://, tcp://); empty leaves the CLI's own. |
timeout_seconds |
60 |
One run's ceiling; past it the CLI's whole process tree is killed. |
max_output_chars |
20000 |
How much one tool answer carries; more is cut and says so. |
default_log_lines |
200 |
The last lines docker_logs reads when a call names no tail. |
max_log_lines |
2000 |
The most last lines one docker_logs call may ask for; a larger tail is refused. |
Read access to a Docker daemon is close to root on that machine: give the cell a daemon you would let the agent see. The cell itself never runs anything but the read-only commands below.
Use it
| Tool | Docker command | For |
|---|---|---|
docker_ps |
docker ps --no-trunc |
The containers: name, short id, image, state, status (uptime, health), published ports and command. Running ones by default; all adds the stopped ones, size their disk size, filters takes KEY=VALUE with id, name, label, status, ancestor, health, network, volume, exited, publish, expose, before, since, is-task. |
docker_logs |
docker logs |
A container's last lines, stdout and stderr: tail (default default_log_lines, at most max_log_lines), since and until (a duration like 10m, a Unix timestamp, or a date-time), timestamps. |
docker_inspect |
docker inspect --type=... |
One container (the default), image, volume or network. A container reads as a summary: state, health, restarts, exit code, command, env, ports, mounts, networks, restart policy, limits, labels. raw answers the whole object as JSON. |
docker_stats |
docker stats --no-stream |
One reading per running container (or the named containers; all adds stopped ones): CPU %, memory used / limit and %, network and block I/O, processes. Never a stream. |
docker_images |
docker images |
The local images: repository:tag, short id, size, age. all adds intermediate images; filters takes dangling, reference, label, before, since, until. |
docker_compose_ps |
docker compose ls / docker compose -p NAME ps |
With no project, every compose project with its status and config files; with one, each service's container, state, health and published ports. |
$ docker ps --no-trunc --format={{json .}} --filter=name=web
exit 0 (ok)
1 container
- shop-web-1 (3f2a9c1b0d4e) shop/web:1.4 running - Up 2 hours (healthy) ports 127.0.0.1:18080->8080/tcp
command: "/app/run --password=[redacted]"
/docker answers the client's and the daemon's versions, or says why no daemon answered.
Read-only, and what is never shown
- No tool can start, stop, restart, remove, exec into, attach to, build, pull, push, copy from or change anything: each tool runs one fixed read-only command, and there is no way to name another.
- Every value a call carries rides its flag as one argument (
--filter=KEY=VALUE,--since=10m), and names, image references, project names, times and filters are checked against what Docker accepts first: a value opening with a dash, or holding a blank, a quote or;, is refused before anything runs. Filter keys come from a fixed list. - Env values: every
Envvalue of an inspected container or image is replaced by[redacted], its name kept. OnlyPATH,HOME,HOSTNAME,LANG,LANGUAGE,LC_ALL,TERM,TZ,PWD,SHLVL,USERand names ending in_VERSIONshow their value, and none of them when the name also names a credential. - Credentials elsewhere: in commands, health checks, every other string of an inspected object (raw too),
docker pscommands, log lines and error output, the value after a credential's name is replaced (password=,token:,"secret": "...", and a bare flag's next word:--requirepass VALUE,--api-key VALUE; a quoted value is replaced whole, blanks and all; a name holdingPASS,SECRET,TOKEN,KEY,AUTH,CRED,COOKIE,SESSION,PRIVATE,SIGNATURE,SALTorDSN, or ending inPWD), and so is a URL's password (postgres://user:[redacted]@host) and the token afterBearerorBasic, however many blanks sit between. A label, option or driver option whose name names a credential has its value replaced. - Logs: before
docker_logsand a container'sdocker_inspectanswer, the container's own credential variables (and any URL password in its Env) are read, and those values are scrubbed wherever they appear, so a program that prints its password does not show it. Every URL password in a variable counts, when one holds several. Values under four characters are not scrubbed, since they would blank ordinary text. All of this runs before an answer is cut tomax_output_chars, so a secret the cut would split leaks no prefix. - The patterns cannot know every secret a program might print in free text; the Env scrub and the name rules cover what a container is given, not what it invents.
Test
.github/test-cell.sh tools/nodecode-docker
The tests run offline: the CLI is a stub that records each command line and answers chosen JSON, so the command lines, the refusals, the redaction of Env, commands, health checks, labels and logs, and the missing-CLI and stopped-daemon words are asserted with no Docker.
License
MIT. See LICENSE. Docker is a separate program; none of its code is included.