qodalis-cli-server-plugin-docker 1.0.0b39__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. qodalis_cli_server_plugin_docker-1.0.0b39/.gitignore +2 -0
  2. qodalis_cli_server_plugin_docker-1.0.0b39/LICENSE +21 -0
  3. qodalis_cli_server_plugin_docker-1.0.0b39/PKG-INFO +300 -0
  4. qodalis_cli_server_plugin_docker-1.0.0b39/README.md +273 -0
  5. qodalis_cli_server_plugin_docker-1.0.0b39/pyproject.toml +57 -0
  6. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/__init__.py +44 -0
  7. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/builder.py +196 -0
  8. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/commands.py +1434 -0
  9. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/compose.py +319 -0
  10. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/console/extension.css +32 -0
  11. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/console/extension.js +89 -0
  12. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/console_page.py +28 -0
  13. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/controller.py +309 -0
  14. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/engine.py +482 -0
  15. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/exec_socket.py +246 -0
  16. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/mcp_tools.py +149 -0
  17. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/plugin.py +36 -0
  18. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/service.py +2007 -0
  19. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/settings.py +172 -0
  20. qodalis_cli_server_plugin_docker-1.0.0b39/qodalis_cli_docker/shapes.py +317 -0
@@ -0,0 +1,2 @@
1
+ qodalis_cli_docker/console/
2
+ node_modules/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Qodalis Solutions
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,300 @@
1
+ Metadata-Version: 2.5
2
+ Name: qodalis-cli-server-plugin-docker
3
+ Version: 1.0.0b39
4
+ Summary: Docker containers, images, stacks, volumes and networks plugin for Qodalis CLI servers: commands, API, MCP, exec socket and Console page
5
+ Project-URL: Homepage, https://github.com/qodalis-solutions/cli-server-python
6
+ Project-URL: Repository, https://github.com/qodalis-solutions/cli-server-python
7
+ Project-URL: Issues, https://github.com/qodalis-solutions/cli-server-python/issues
8
+ Author-email: Nicolae Lupei <nicolae.lupei@qodalis.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: cli,containers,docker,plugin,qodalis
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: fastapi>=0.100.0
22
+ Requires-Dist: opentelemetry-api<1.46
23
+ Requires-Dist: qodalis-cli-server-abstractions>=1.0.0b39
24
+ Provides-Extra: users
25
+ Requires-Dist: qodalis-cli-server-plugin-users>=1.0.0b39; extra == 'users'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # qodalis-cli-server-plugin-docker
29
+
30
+ Docker for the [Qodalis CLI Server (Python)](https://github.com/qodalis-solutions/cli-server-python): containers, images,
31
+ compose stacks, volumes and networks of one or more Docker hosts, through the Docker Engine API, from the Qodalis Console
32
+ (a Docker page), the web terminal (`docker`), MCP and a REST API, with an interactive exec session in the Console. The
33
+ design and the contract shared with the Node and .NET servers is
34
+ `web-cli/docs/superpowers/specs/2026-12-04-docker-plugin-design.md`.
35
+
36
+ ```bash
37
+ pip install qodalis-cli-server-plugin-docker
38
+ ```
39
+
40
+ The plugin is opt-in and has no default endpoint: the Docker socket is root-equivalent, so the server's owner says which
41
+ engine to use. Without an `endpoint` the plugin is **needs configuration** (it registers nothing).
42
+
43
+ ## Use
44
+
45
+ ```python
46
+ from qodalis_cli import create_cli_server
47
+ from qodalis_cli_docker import plugin as docker
48
+
49
+ result = create_cli_server(CliServerOptions(
50
+ configure=lambda builder: builder.add_plugin(docker, {"endpoint": "unix:///var/run/docker.sock", "protect": ["postgres*"]}),
51
+ ))
52
+ ```
53
+
54
+ or without the plugin loader:
55
+
56
+ ```python
57
+ from qodalis_cli_docker import CliDockerBuilder, DockerSettings
58
+
59
+ plugin = (
60
+ CliDockerBuilder()
61
+ .set_settings(lambda: DockerSettings(endpoint="unix:///var/run/docker.sock", protect=["postgres*"]))
62
+ .set_audit(record) # optional: an async function of the audit entry (a dict)
63
+ .build()
64
+ )
65
+ result.mount_plugin(plugin) # routes, commands, permissions, the Console page, the MCP tools and the exec socket
66
+ ```
67
+
68
+ The demo server enables the plugin only when `QCLI_DOCKER_ENDPOINT` is set (its value is the endpoint); it is protected
69
+ (users plugin), so the plugin serves signed-in callers; `QCLI_DOCKER_ALLOW_UNPROTECTED=true` turns `allowUnprotected` on.
70
+
71
+ ## Settings
72
+
73
+ Config provider `docker`, section `settings` (Console Config page, `config set docker.settings.<key> <value>`). They are
74
+ read on every call, so a change applies without a restart, except hosts and TLS files, which apply to new connections.
75
+
76
+ | Key | Type | Default | Meaning |
77
+ |---|---|---|---|
78
+ | `endpoint` | string, required | none | The default host (named `local`): `unix:///var/run/docker.sock`, `tcp://host:2375`, `tcp://host:2376` (TLS when a certificate is set or the port is 2376), `https://host:2376` |
79
+ | `tlsCa`, `tlsCert`, `tlsKey` | string | none | Paths of PEM files for the default host |
80
+ | `tlsVerify` | boolean | true | Verify the engine's certificate |
81
+ | `hosts` | json | `{}` | More hosts: `{ "<name>": { "endpoint": "...", "tlsCa": "...", "tlsCert": "...", "tlsKey": "...", "tlsVerify": true } }`; names match `^[a-z0-9][a-z0-9-]{0,31}$`, `local` is reserved; invalid entries are dropped and logged |
82
+ | `readOnly` | boolean | false | Refuse every change (actions, pulls, exec, removals, prunes, creation) |
83
+ | `hide` | string[] | `[]` | Containers nobody sees (404, left out of lists, counts, stacks, events) |
84
+ | `protect` | string[] | `[]` | Containers that can be read but not changed (409 `container <name> is protected`) |
85
+ | `composeRoots` | string[] | `[]` | The only folders compose files are read from, written to and run from (absolute paths); empty: no compose file is read and no compose feature works |
86
+ | `composeCommand` | string | `docker compose` | The compose CLI: words split like a shell line, run without a shell (`docker-compose` works too) |
87
+ | `composeHosts` | string[] | `["local"]` | The hosts compose may change; write, `up`, compose `down` and delete on another host are 409 `compose is not enabled for host <name>` (the Engine API way of `down` for a stack without a file works on any host) |
88
+ | `composeEnv` | string[] | `[]` | Names of the server's environment variables the compose CLI may see (for `${VAR}` in compose files); names starting with `DOCKER_` or `COMPOSE_` are ignored |
89
+ | `composeTimeoutSeconds` | number 10-3600 | 900 | Time limit of one compose `up` (`down` has 120 s) |
90
+ | `allowUnprotected` | boolean | false | Serve callers that are not signed in (a server without the users plugin's protection); off: see the first rule below |
91
+ | `timeoutSeconds` | number 1-120 | 15 | Timeout of one Engine API call (not of streams, pulls or exec) |
92
+
93
+ A pattern of `hide` / `protect` is a container name with `*` wildcards (`postgres*`, case-sensitive, matched against the
94
+ name without the leading `/`), or `label:<key>` / `label:<key>=<value>`. Every route takes `?host=<name>`, every command
95
+ `--host <name>`; an unknown name is 404 / `Error: unknown Docker host: <name>`.
96
+
97
+ ## Permissions
98
+
99
+ | Permission | Allows |
100
+ |---|---|
101
+ | `docker:read` | See containers, images, stacks, volumes, networks, logs and stats |
102
+ | `docker:manage` | Start, stop and restart containers and stacks, pull images |
103
+ | `docker:exec` | Run commands inside containers (REST, terminal, MCP and the exec socket) |
104
+ | `docker:admin` | Remove containers and images, prune, create and remove volumes and networks, take stacks down |
105
+
106
+ On a protected server the route gate maps GET to the first permission and other methods to the second of each path:
107
+ `/api/v1/qcli/docker` `docker:read` / `docker:manage`, `/exec` `docker:exec`, `/admin` `docker:admin`. The exec socket needs
108
+ `docker:exec` (the plugin checks it itself); the root command `docker` needs `docker:read` and each sub-command adds its own.
109
+
110
+ ## REST API (`/api/v1/qcli/docker`)
111
+
112
+ Errors are `{ "error": "<text>" }`: 400 invalid input or an ambiguous container reference, 403 `the Docker plugin is
113
+ read-only` or `the Docker plugin needs a protected server (sign-in); see its allowUnprotected setting`, 404 unknown host,
114
+ container, image, volume, network, stack or operation, 409 `container <name> is protected` or the engine's own conflict,
115
+ 502 `cannot reach Docker at <host>: <message>`, 504 an exec that did not finish. A container reference is a full id, an id
116
+ prefix of at least 3 characters or a name.
117
+
118
+ | Route | Permission | Answer |
119
+ |---|---|---|
120
+ | `GET /hosts` | read | `{ hosts, readOnly }` (each host probed with a 3 s timeout) |
121
+ | `GET /info`, `/df` | read | engine info; disk usage with reclaimable sizes |
122
+ | `GET /events?since=&limit=` | read | `{ host, events }`, newest first |
123
+ | `GET /containers?all=&stack=`, `/containers/{id}` | read | containers sorted by name; one with its detail (command, masked environment, mounts, networks) |
124
+ | `GET /containers/{id}/logs?tail=&since=&timestamps=` | read | `{ host, lines }`, oldest first |
125
+ | `GET /stats?ids=` | read | CPU, memory, network, block I/O and pids (two samples per container) |
126
+ | `GET /compose` | read | `{ available, version?, roots, error? }`: whether the compose CLI answers (`version --short`, 5 s, cached 60 s) |
127
+ | `GET /images`, `/stacks`, `/stacks/{name}`, `/volumes[/{name}]`, `/networks[/{id}]` | read | lists and details; a stack has `composeFile` (the path found by the rule) and the state `down` when only its folder exists |
128
+ | `GET /operations`, `/operations/{id}` | read | the last 50 operations (pulls, stack updates), newest first |
129
+ | `POST /containers/{id}/start\|stop\|restart\|kill\|pause\|unpause` | manage | `{ ok, container }` |
130
+ | `POST /images/pull` `{ image }` | manage | 202 `{ operation }`; the pull runs in the background |
131
+ | `POST /stacks/{name}/start\|stop\|restart` | manage | `{ ok, results }` per container (a protected one is reported, the rest run) |
132
+ | `POST /stacks/{name}/pull` | manage | 202 `{ operation }` |
133
+ | `POST /exec/{id}` `{ command, user?, workdir?, timeoutSeconds? }` | exec | `{ exitCode, stdout, stderr, truncated }` (1 MB per stream; 504 on timeout) |
134
+ | `DELETE /admin/containers/{id}?force=&volumes=`, `POST /admin/containers/prune` | admin | `{ ok }`; `{ removed, reclaimedBytes }` (hidden and protected containers are never pruned) |
135
+ | `DELETE /admin/images/{id}?force=`, `POST /admin/images/prune` `{ all? }` | admin | `{ ok, untagged, deleted }`; `{ removed, reclaimedBytes }` |
136
+ | `POST /admin/volumes`, `DELETE /admin/volumes/{name}?force=`, `POST /admin/volumes/prune` | admin | 201 `{ volume }`; `{ ok }`; `{ removed, reclaimedBytes }` |
137
+ | `POST /admin/networks`, `DELETE /admin/networks/{id}`, `POST /admin/networks/prune` | admin | 201 `{ network }`; `{ ok }` (a built-in network is 409); `{ removed }` |
138
+ | `POST /admin/stacks/{name}/down` body `{ volumes? }` | admin | a stack with a compose file: `compose down` (`--volumes`), 120 s; without a file the Engine API way: stops and removes the containers, then the stack's networks; refused whole (409) with a protected container |
139
+ | `PUT /admin/stacks/{name}/compose` body `{ content }` | admin | writes the stack's compose file after `config --quiet` accepted it; `{ stack, composeFile }` |
140
+ | `POST /admin/stacks/{name}/up` body `{ pull?, file? }` | admin | 202 `{ operation }` (kind `stack-up`, with the CLI's `log`) |
141
+ | `DELETE /admin/stacks/{name}/compose` | admin | removes the file of a stack that is down |
142
+
143
+ `stacks start` starts the stack's existing containers; creating and updating stacks is the Compose feature below (the
144
+ Engine API has no compose).
145
+
146
+ A pull publishes `docker:operation` on the event bus (data: the operation, audience `docker:read`) on each state change
147
+ and at most once a second while its progress changes.
148
+
149
+ ## Exec socket
150
+
151
+ `WS /ws/v1/qcli/docker/exec?host=&container=&cmd=&user=&cols=&rows=&ticket=` (also `/ws/qcli/docker/exec`): an
152
+ interactive session with a TTY. `cmd` defaults to `/bin/sh -c 'command -v bash >/dev/null 2>&1 && exec bash || exec sh'`.
153
+ The messages are those of `/ws/v1/qcli/shell`: the client sends `{ "type": "stdin", "data" }` and
154
+ `{ "type": "resize", "cols", "rows" }`; the server `{ "type": "ready", "shell", "os" }` (`shell` is a short label: `sh` for
155
+ the default shell, else the first word of `cmd`), `{ "type": "stdout", "data" }`, `{ "type": "exit", "code" }` and
156
+ `{ "type": "error", "message" }`. Closing the socket ends the exec. Hidden and protected containers, read-only mode, an
157
+ unknown host or container, a container that is not running and an unreachable engine are refused with ONE message
158
+ `{ "type": "error", "message" }` (the text of the matching REST error) and a normal close (1000), because a browser cannot
159
+ read the status of a refused upgrade. The server's own origin check applies (a foreign origin is closed with 4403 `origin
160
+ not allowed`); a protected server closes with 4401 `unauthorized` (no or a used ticket) or 4403 `forbidden` (no
161
+ `docker:exec`), like the shell socket. `docker exec -it <container> [command...]` in a web terminal that can run sessions
162
+ (`sessions: true` in the request) answers with a `session` block that points at this socket (the container, `cmd`, `user`);
163
+ `docker exec <container>` without a command does too.
164
+
165
+ ## Terminal commands
166
+
167
+ Output v2 (typed tables, status tones, key-value panels, progress); `--host <name>` everywhere, `--json` where data is
168
+ printed (the route's answer indented by 2); destructive commands ask first (`--yes`, `-y`).
169
+
170
+ | Command | Permission | Notes |
171
+ |---|---|---|
172
+ | `docker` | read | the hosts, a summary of the default host, the sub-commands |
173
+ | `docker hosts` | read | name, endpoint, state, version, containers |
174
+ | `docker ps [--all] [--stack <name>]` | read | running containers unless `--all`; a row opens `docker inspect` |
175
+ | `docker inspect <container>` | read | panels: container, ports, mounts, networks, environment |
176
+ | `docker logs <container> [--tail <n>] [--since <10m\|2h\|ISO>] [--timestamps] [--follow]` | read | `--follow` streams until stopped (streaming terminals) |
177
+ | `docker stats [container] [--watch]` | read | `--watch` refreshes the table every 2 s |
178
+ | `docker start\|stop\|restart\|kill\|pause\|unpause <container...>` | manage | one line per container; exit 1 when any failed |
179
+ | `docker rm <container...> [--force] [--volumes] [--yes]` | admin | asks first |
180
+ | `docker exec [options] <container> [<command...>]` | exec | options `-i`, `-t`, `-it`, `--interactive`, `--tty`, `--user`/`-u`, `--workdir`/`-w`, `--timeout <s>`, `--host` go BEFORE the container (as in the docker CLI); everything after the container is the command, flags included, taken from the raw line and split like a shell line: `docker exec web ls -la /`, `docker exec -u root web sh -c "echo a; exit 3"`. Output: stdout, then stderr (warning); the command's exit code |
181
+ | `docker images`, `docker images prune [--all] [--yes]` | read; admin | |
182
+ | `docker pull <image>` | manage | progress until done |
183
+ | `docker rmi <image...> [--force] [--yes]` | admin | asks first |
184
+ | `docker stacks`, `stacks show <name>` | read | the compose file is shown when it can be read; a folder with a compose file and no containers is listed as `down` |
185
+ | `docker stacks start\|stop\|restart\|pull <name>` | manage | |
186
+ | `docker stacks up <name> [--file <path>] [--pull]` | admin | compose up; a progress block labelled with the last output line, the log as a code block when it fails |
187
+ | `docker stacks down <name> [--volumes] [--yes]` | admin | asks first |
188
+ | `docker stacks rm <name> [--yes]` | admin | deletes the compose file of a stack that is down; asks first |
189
+ | `docker compose ...` | | `compose` is an alias of `stacks` (`docker compose up shop`) |
190
+ | `docker volumes`, `volumes inspect <name>` | read | |
191
+ | `docker volumes create <name> [--driver <d>]`, `rm <name...> [--force] [--yes]`, `prune [--yes]` | admin | |
192
+ | `docker networks`, `networks inspect <name>` | read | |
193
+ | `docker networks create <name> [--driver <d>] [--internal] [--subnet <cidr>]`, `rm <name...> [--yes]`, `prune [--yes]` | admin | |
194
+ | `docker system info`, `system df`, `system events [--since <1h>] [--follow]` | read | |
195
+
196
+ ## Compose
197
+
198
+ Stacks can be created, updated and removed from their compose file. This runs the `docker compose` CLI on the machine
199
+ the server runs on (the Engine API cannot do it), so **the CLI must be installed there**, for example in the server's own
200
+ container image, and the files must be under `composeRoots`: no root, no compose feature (every route answers 409 with the
201
+ text of `GET /compose`).
202
+
203
+ - Settings: `composeRoots` (the only folders files are read from, written to and run from; absolute paths only),
204
+ `composeCommand` (default `docker compose`; `docker-compose` works, except on a TLS host) and `composeTimeoutSeconds` (900).
205
+ - Compose runs on the server's machine and **resolves `env_file`, build contexts, file secrets and `include`s on the server's disk**
206
+ (and sends them to the engine), so compose is on for the host `local` only unless `composeHosts` lists more hosts.
207
+ - The file of stack `<name>` is the first of: the stack's `com.docker.compose.project.config_files` label (when the host is
208
+ a unix socket and it passes the checks of the roots), `<root>/<name>/compose.yaml`, `compose.yml`, `docker-compose.yml`,
209
+ `docker-compose.yaml` (the folder `<root>/<name>` must be a real folder directly under the root, not a link). Every path is
210
+ checked the same way: absolute, `.yml`/`.yaml`, real path under a root, regular file, at most 256 KB. A folder directly
211
+ under a root with one of those files and a valid name (`^[a-z0-9][a-z0-9_-]{0,62}$`) is a stack even without containers:
212
+ it is listed with the state `down` (at most 200 folders per root); a project that has containers, hidden ones too, is never
213
+ `down`, and a project whose containers are all hidden does not exist (`GET /stacks/<name>` is 404).
214
+ - `PUT .../compose` checks the content with `<composeCommand> --project-name=<name> --file=<temp file in the same folder> config --quiet`
215
+ (a failure is 400 with compose's message, the temp file's path replaced by `compose.yaml`; nothing changes), then renames
216
+ the temp file over the target: the existing file (it keeps the file's mode; a new file is 0644), or
217
+ `<first existing root>/<name>/compose.yaml` (the folder is created, and removed again when the write fails). The target and
218
+ its folder are never links.
219
+ - `POST .../up` is an operation of kind `stack-up` (`--project-name=<name> --file=<real path> up -d --remove-orphans`,
220
+ `--pull always` with `pull`, in the file's folder, killed at `composeTimeoutSeconds`). `file` only serves a stack with no
221
+ file by the rule. Its `log` holds the last 200 lines of the CLI's output (stdout and stderr merged, ANSI codes stripped,
222
+ lines cut at 2000 characters); `message` is the last line. The `log` and `message` of a `stack-up` are shown only to
223
+ `docker:admin` (`GET /operations`, `GET /operations/{id}` and the `docker:operation` event, personalised per socket; the
224
+ others get `log: []` and no `message`), because compose output can quote values. One stack has at most one running `up`
225
+ (409), it counts towards the 5 running operations, and `down`, a write and a delete of that stack are 409
226
+ `stack <name> is already being updated` meanwhile. At most 5 other compose processes (checks, `down`) run at once.
227
+ `down` with a file is `compose down` (`--volumes` with `volumes`), 120 s, 504 on timeout; `volumes` without a file is 400
228
+ `volumes needs a compose file`.
229
+ - The CLI is started without a shell from an argument list, with the host's connection always as docker's global flags, the
230
+ default socket included (`--host`, `--tlsverify --tlscacert --tlscert --tlskey`; `docker-compose` gets `DOCKER_HOST`), so a
231
+ docker context or `DOCKER_HOST` of the server can never pick another engine. Its environment is minimal: `PATH`, `HOME`,
232
+ `USER`, `LANG`, `TMPDIR`, the names in `composeEnv`, and `COMPOSE_INTERACTIVE_NO_CLI=1`, `COMPOSE_MENU=false`, `NO_COLOR=1`.
233
+ Its output is never interpreted, only shown. The running processes are killed (with their process group) at the time limit
234
+ and when the plugin stops. The audit of a failed write or `up` says `compose exited with code <n>`, never compose's message.
235
+ - `up` and compose `down` are refused (409) when the stack has a protected container (`container <name> is protected`) or
236
+ a hidden one (`stack <name> has containers this plugin may not change`). Changes are audited (`docker.stack.up`,
237
+ `docker.stack.down`, `docker.stack.compose.write`, `docker.stack.compose.remove`; the content is not recorded).
238
+ - The demo reads `QCLI_DOCKER_COMPOSE_ROOTS` (comma separated).
239
+
240
+ ## MCP tools
241
+
242
+ The commands are MCP tools like every command (with their permissions); besides them the provider `docker` offers
243
+ structured tools returning the REST shapes: `docker_list_containers`, `docker_inspect_container`, `docker_logs`,
244
+ `docker_stats`, `docker_list_images`, `docker_list_stacks`, `docker_system_info` (`docker:read`, read-only hint),
245
+ `docker_start`, `docker_stop`, `docker_restart` (`docker:manage`) and `docker_exec` (`docker:exec`, destructive hint).
246
+ The structured provider has no remove or prune tool.
247
+
248
+ ## Rules that hold for routes, commands, the socket and MCP alike
249
+
250
+ - Sign-in: the Docker socket is root-equivalent, so unless `allowUnprotected` is on a call without a signed-in caller (a
251
+ server that is not protected) is refused everywhere: routes 403 `the Docker plugin needs a protected server (sign-in);
252
+ see its allowUnprotected setting`, commands the same text after `Error: `, MCP tools the same error, the exec socket
253
+ closes 4401 `login required`. The check is one method of the service, `assert_caller`, called once per call.
254
+ - `readOnly` refuses every change, including exec. Hidden containers do not exist. Protected containers can be read but
255
+ not changed (actions, rm, exec, prune, stack actions on them).
256
+ - Every change is recorded in the server's audit log when it has one: event `docker.<object>.<action>`
257
+ (`docker.container.restart`, `docker.image.pull`, `docker.exec.run`, `docker.exec.session`, `docker.stack.down`,
258
+ `docker.volumes.prune`, ...), `target` `docker:<host>/<kind>/<name>`, `properties` `{ host, ... }`; the command of an exec
259
+ is recorded, its output is not; failures carry `properties.error`, and so do changes refused by read-only mode or
260
+ protection (hidden containers do not exist, so they leave no entry).
261
+ - A protected container, running or not, refuses `stacks down` of its stack whole; with hidden containers in the stack,
262
+ `stacks down` leaves them and the stack's networks alone. `networks prune` is done by the plugin (not the engine's
263
+ prune): it removes the unused custom networks and leaves those a hidden or protected container is attached to.
264
+ - Hidden containers also stay out of events: an event of another type that names one in its attributes is dropped.
265
+ - The exec socket's `exit` message carries the exec's real exit code; the exec of a client that leaves while the session
266
+ starts is ended. An open exec session ends (close 4401 `permission removed`) when its user loses `docker:exec`, and with 4401
267
+ `session ended` when its session ends (logout, revoke, expiry, user disabled); re-checked on every change and every 30 s
268
+ like the shell socket.
269
+ - A stack's compose file is the first of the label `com.docker.compose.project.config_files` (only on a unix socket host and
270
+ only when it passes the checks of `composeRoots`) and the file of the root's sub-folder (see Compose). The label is
271
+ written by whoever created the container, so it is never trusted; anything that fails a check is `composeFile: null`.
272
+ - Cross-site: with `allowUnprotected`, a change by a caller without a principal (any route but GET, HEAD and OPTIONS, and the exec socket) that carries an `Origin` whose host:port differs from the request's `Host` is refused: 403 / close 4403 `cross-site requests are refused` (an absent Origin passes, `null` counts as cross-site). A principal always needs `docker:exec` on the exec socket, also on a server that is not protected.
273
+ - The `log` and `message` of a `stack-up` go to `docker:admin`, and to a caller without a principal only with `allowUnprotected`.
274
+ - A timed-out one-off exec (`504`) may keep running in the container: the Engine API cannot kill an exec.
275
+ - Pulls: at most 5 run at once (`409 too many operations are running (5 at most)`); a pull whose connection drops or that
276
+ receives nothing for 120 s fails. `GET /stats` takes at most 100 ids (`400 too many ids (100 at most)`) and samples at
277
+ most 10 containers at a time. A log line longer than 16 KB is cut and ends with `…`.
278
+ - Error texts never contain file-system paths of TLS files: an unreadable one is `cannot read the TLS files of <host>`.
279
+ - Nothing the plugin answers contains TLS key paths, registry credentials or unmasked secret-like environment values
280
+ (names containing password, passwd, secret, token, key, credential or auth show `••••••`).
281
+
282
+ ## Console page
283
+
284
+ The page is the Console module `@qodalis/console-module-docker` (group Operations, `docker:read`, with an Overview card),
285
+ embedded into the wheel by `scripts/copy_console.py` and served at `/qcli/modules/docker`; `set_console_dir(False)` leaves
286
+ it out (as does a build without the module: the plugin works without the page).
287
+
288
+ ## Engine client
289
+
290
+ The plugin talks to the Engine API with a small HTTP/1.1 client on `asyncio` streams (unix socket, TCP, TLS; chunked
291
+ streams and the connection upgrade of an exec), not with `aiodocker` or `httpx`: it has no dependency besides FastAPI, and
292
+ the streams it needs (logs, events, pulls, a hijacked exec) are controlled byte by byte.
293
+
294
+ ## Tests
295
+
296
+ `tests/test_docker_*.py` of the server run against a fake Engine API (`tests/docker_fake_engine.py`) fed from
297
+ `fixtures/engine/*.json`; `fixtures/README.md` says which engine request maps to which file. The expected `/execute`
298
+ answers (`fixtures/expected/commands.v2.jsonl`, `commands.v1.jsonl`) and REST answers (`fixtures/expected/rest/*.json`)
299
+ are copied from the Node server (its generator writes them); the Python tests (`tests/test_docker_expected.py`) must
300
+ produce the same, byte for byte for the commands.
@@ -0,0 +1,273 @@
1
+ # qodalis-cli-server-plugin-docker
2
+
3
+ Docker for the [Qodalis CLI Server (Python)](https://github.com/qodalis-solutions/cli-server-python): containers, images,
4
+ compose stacks, volumes and networks of one or more Docker hosts, through the Docker Engine API, from the Qodalis Console
5
+ (a Docker page), the web terminal (`docker`), MCP and a REST API, with an interactive exec session in the Console. The
6
+ design and the contract shared with the Node and .NET servers is
7
+ `web-cli/docs/superpowers/specs/2026-12-04-docker-plugin-design.md`.
8
+
9
+ ```bash
10
+ pip install qodalis-cli-server-plugin-docker
11
+ ```
12
+
13
+ The plugin is opt-in and has no default endpoint: the Docker socket is root-equivalent, so the server's owner says which
14
+ engine to use. Without an `endpoint` the plugin is **needs configuration** (it registers nothing).
15
+
16
+ ## Use
17
+
18
+ ```python
19
+ from qodalis_cli import create_cli_server
20
+ from qodalis_cli_docker import plugin as docker
21
+
22
+ result = create_cli_server(CliServerOptions(
23
+ configure=lambda builder: builder.add_plugin(docker, {"endpoint": "unix:///var/run/docker.sock", "protect": ["postgres*"]}),
24
+ ))
25
+ ```
26
+
27
+ or without the plugin loader:
28
+
29
+ ```python
30
+ from qodalis_cli_docker import CliDockerBuilder, DockerSettings
31
+
32
+ plugin = (
33
+ CliDockerBuilder()
34
+ .set_settings(lambda: DockerSettings(endpoint="unix:///var/run/docker.sock", protect=["postgres*"]))
35
+ .set_audit(record) # optional: an async function of the audit entry (a dict)
36
+ .build()
37
+ )
38
+ result.mount_plugin(plugin) # routes, commands, permissions, the Console page, the MCP tools and the exec socket
39
+ ```
40
+
41
+ The demo server enables the plugin only when `QCLI_DOCKER_ENDPOINT` is set (its value is the endpoint); it is protected
42
+ (users plugin), so the plugin serves signed-in callers; `QCLI_DOCKER_ALLOW_UNPROTECTED=true` turns `allowUnprotected` on.
43
+
44
+ ## Settings
45
+
46
+ Config provider `docker`, section `settings` (Console Config page, `config set docker.settings.<key> <value>`). They are
47
+ read on every call, so a change applies without a restart, except hosts and TLS files, which apply to new connections.
48
+
49
+ | Key | Type | Default | Meaning |
50
+ |---|---|---|---|
51
+ | `endpoint` | string, required | none | The default host (named `local`): `unix:///var/run/docker.sock`, `tcp://host:2375`, `tcp://host:2376` (TLS when a certificate is set or the port is 2376), `https://host:2376` |
52
+ | `tlsCa`, `tlsCert`, `tlsKey` | string | none | Paths of PEM files for the default host |
53
+ | `tlsVerify` | boolean | true | Verify the engine's certificate |
54
+ | `hosts` | json | `{}` | More hosts: `{ "<name>": { "endpoint": "...", "tlsCa": "...", "tlsCert": "...", "tlsKey": "...", "tlsVerify": true } }`; names match `^[a-z0-9][a-z0-9-]{0,31}$`, `local` is reserved; invalid entries are dropped and logged |
55
+ | `readOnly` | boolean | false | Refuse every change (actions, pulls, exec, removals, prunes, creation) |
56
+ | `hide` | string[] | `[]` | Containers nobody sees (404, left out of lists, counts, stacks, events) |
57
+ | `protect` | string[] | `[]` | Containers that can be read but not changed (409 `container <name> is protected`) |
58
+ | `composeRoots` | string[] | `[]` | The only folders compose files are read from, written to and run from (absolute paths); empty: no compose file is read and no compose feature works |
59
+ | `composeCommand` | string | `docker compose` | The compose CLI: words split like a shell line, run without a shell (`docker-compose` works too) |
60
+ | `composeHosts` | string[] | `["local"]` | The hosts compose may change; write, `up`, compose `down` and delete on another host are 409 `compose is not enabled for host <name>` (the Engine API way of `down` for a stack without a file works on any host) |
61
+ | `composeEnv` | string[] | `[]` | Names of the server's environment variables the compose CLI may see (for `${VAR}` in compose files); names starting with `DOCKER_` or `COMPOSE_` are ignored |
62
+ | `composeTimeoutSeconds` | number 10-3600 | 900 | Time limit of one compose `up` (`down` has 120 s) |
63
+ | `allowUnprotected` | boolean | false | Serve callers that are not signed in (a server without the users plugin's protection); off: see the first rule below |
64
+ | `timeoutSeconds` | number 1-120 | 15 | Timeout of one Engine API call (not of streams, pulls or exec) |
65
+
66
+ A pattern of `hide` / `protect` is a container name with `*` wildcards (`postgres*`, case-sensitive, matched against the
67
+ name without the leading `/`), or `label:<key>` / `label:<key>=<value>`. Every route takes `?host=<name>`, every command
68
+ `--host <name>`; an unknown name is 404 / `Error: unknown Docker host: <name>`.
69
+
70
+ ## Permissions
71
+
72
+ | Permission | Allows |
73
+ |---|---|
74
+ | `docker:read` | See containers, images, stacks, volumes, networks, logs and stats |
75
+ | `docker:manage` | Start, stop and restart containers and stacks, pull images |
76
+ | `docker:exec` | Run commands inside containers (REST, terminal, MCP and the exec socket) |
77
+ | `docker:admin` | Remove containers and images, prune, create and remove volumes and networks, take stacks down |
78
+
79
+ On a protected server the route gate maps GET to the first permission and other methods to the second of each path:
80
+ `/api/v1/qcli/docker` `docker:read` / `docker:manage`, `/exec` `docker:exec`, `/admin` `docker:admin`. The exec socket needs
81
+ `docker:exec` (the plugin checks it itself); the root command `docker` needs `docker:read` and each sub-command adds its own.
82
+
83
+ ## REST API (`/api/v1/qcli/docker`)
84
+
85
+ Errors are `{ "error": "<text>" }`: 400 invalid input or an ambiguous container reference, 403 `the Docker plugin is
86
+ read-only` or `the Docker plugin needs a protected server (sign-in); see its allowUnprotected setting`, 404 unknown host,
87
+ container, image, volume, network, stack or operation, 409 `container <name> is protected` or the engine's own conflict,
88
+ 502 `cannot reach Docker at <host>: <message>`, 504 an exec that did not finish. A container reference is a full id, an id
89
+ prefix of at least 3 characters or a name.
90
+
91
+ | Route | Permission | Answer |
92
+ |---|---|---|
93
+ | `GET /hosts` | read | `{ hosts, readOnly }` (each host probed with a 3 s timeout) |
94
+ | `GET /info`, `/df` | read | engine info; disk usage with reclaimable sizes |
95
+ | `GET /events?since=&limit=` | read | `{ host, events }`, newest first |
96
+ | `GET /containers?all=&stack=`, `/containers/{id}` | read | containers sorted by name; one with its detail (command, masked environment, mounts, networks) |
97
+ | `GET /containers/{id}/logs?tail=&since=&timestamps=` | read | `{ host, lines }`, oldest first |
98
+ | `GET /stats?ids=` | read | CPU, memory, network, block I/O and pids (two samples per container) |
99
+ | `GET /compose` | read | `{ available, version?, roots, error? }`: whether the compose CLI answers (`version --short`, 5 s, cached 60 s) |
100
+ | `GET /images`, `/stacks`, `/stacks/{name}`, `/volumes[/{name}]`, `/networks[/{id}]` | read | lists and details; a stack has `composeFile` (the path found by the rule) and the state `down` when only its folder exists |
101
+ | `GET /operations`, `/operations/{id}` | read | the last 50 operations (pulls, stack updates), newest first |
102
+ | `POST /containers/{id}/start\|stop\|restart\|kill\|pause\|unpause` | manage | `{ ok, container }` |
103
+ | `POST /images/pull` `{ image }` | manage | 202 `{ operation }`; the pull runs in the background |
104
+ | `POST /stacks/{name}/start\|stop\|restart` | manage | `{ ok, results }` per container (a protected one is reported, the rest run) |
105
+ | `POST /stacks/{name}/pull` | manage | 202 `{ operation }` |
106
+ | `POST /exec/{id}` `{ command, user?, workdir?, timeoutSeconds? }` | exec | `{ exitCode, stdout, stderr, truncated }` (1 MB per stream; 504 on timeout) |
107
+ | `DELETE /admin/containers/{id}?force=&volumes=`, `POST /admin/containers/prune` | admin | `{ ok }`; `{ removed, reclaimedBytes }` (hidden and protected containers are never pruned) |
108
+ | `DELETE /admin/images/{id}?force=`, `POST /admin/images/prune` `{ all? }` | admin | `{ ok, untagged, deleted }`; `{ removed, reclaimedBytes }` |
109
+ | `POST /admin/volumes`, `DELETE /admin/volumes/{name}?force=`, `POST /admin/volumes/prune` | admin | 201 `{ volume }`; `{ ok }`; `{ removed, reclaimedBytes }` |
110
+ | `POST /admin/networks`, `DELETE /admin/networks/{id}`, `POST /admin/networks/prune` | admin | 201 `{ network }`; `{ ok }` (a built-in network is 409); `{ removed }` |
111
+ | `POST /admin/stacks/{name}/down` body `{ volumes? }` | admin | a stack with a compose file: `compose down` (`--volumes`), 120 s; without a file the Engine API way: stops and removes the containers, then the stack's networks; refused whole (409) with a protected container |
112
+ | `PUT /admin/stacks/{name}/compose` body `{ content }` | admin | writes the stack's compose file after `config --quiet` accepted it; `{ stack, composeFile }` |
113
+ | `POST /admin/stacks/{name}/up` body `{ pull?, file? }` | admin | 202 `{ operation }` (kind `stack-up`, with the CLI's `log`) |
114
+ | `DELETE /admin/stacks/{name}/compose` | admin | removes the file of a stack that is down |
115
+
116
+ `stacks start` starts the stack's existing containers; creating and updating stacks is the Compose feature below (the
117
+ Engine API has no compose).
118
+
119
+ A pull publishes `docker:operation` on the event bus (data: the operation, audience `docker:read`) on each state change
120
+ and at most once a second while its progress changes.
121
+
122
+ ## Exec socket
123
+
124
+ `WS /ws/v1/qcli/docker/exec?host=&container=&cmd=&user=&cols=&rows=&ticket=` (also `/ws/qcli/docker/exec`): an
125
+ interactive session with a TTY. `cmd` defaults to `/bin/sh -c 'command -v bash >/dev/null 2>&1 && exec bash || exec sh'`.
126
+ The messages are those of `/ws/v1/qcli/shell`: the client sends `{ "type": "stdin", "data" }` and
127
+ `{ "type": "resize", "cols", "rows" }`; the server `{ "type": "ready", "shell", "os" }` (`shell` is a short label: `sh` for
128
+ the default shell, else the first word of `cmd`), `{ "type": "stdout", "data" }`, `{ "type": "exit", "code" }` and
129
+ `{ "type": "error", "message" }`. Closing the socket ends the exec. Hidden and protected containers, read-only mode, an
130
+ unknown host or container, a container that is not running and an unreachable engine are refused with ONE message
131
+ `{ "type": "error", "message" }` (the text of the matching REST error) and a normal close (1000), because a browser cannot
132
+ read the status of a refused upgrade. The server's own origin check applies (a foreign origin is closed with 4403 `origin
133
+ not allowed`); a protected server closes with 4401 `unauthorized` (no or a used ticket) or 4403 `forbidden` (no
134
+ `docker:exec`), like the shell socket. `docker exec -it <container> [command...]` in a web terminal that can run sessions
135
+ (`sessions: true` in the request) answers with a `session` block that points at this socket (the container, `cmd`, `user`);
136
+ `docker exec <container>` without a command does too.
137
+
138
+ ## Terminal commands
139
+
140
+ Output v2 (typed tables, status tones, key-value panels, progress); `--host <name>` everywhere, `--json` where data is
141
+ printed (the route's answer indented by 2); destructive commands ask first (`--yes`, `-y`).
142
+
143
+ | Command | Permission | Notes |
144
+ |---|---|---|
145
+ | `docker` | read | the hosts, a summary of the default host, the sub-commands |
146
+ | `docker hosts` | read | name, endpoint, state, version, containers |
147
+ | `docker ps [--all] [--stack <name>]` | read | running containers unless `--all`; a row opens `docker inspect` |
148
+ | `docker inspect <container>` | read | panels: container, ports, mounts, networks, environment |
149
+ | `docker logs <container> [--tail <n>] [--since <10m\|2h\|ISO>] [--timestamps] [--follow]` | read | `--follow` streams until stopped (streaming terminals) |
150
+ | `docker stats [container] [--watch]` | read | `--watch` refreshes the table every 2 s |
151
+ | `docker start\|stop\|restart\|kill\|pause\|unpause <container...>` | manage | one line per container; exit 1 when any failed |
152
+ | `docker rm <container...> [--force] [--volumes] [--yes]` | admin | asks first |
153
+ | `docker exec [options] <container> [<command...>]` | exec | options `-i`, `-t`, `-it`, `--interactive`, `--tty`, `--user`/`-u`, `--workdir`/`-w`, `--timeout <s>`, `--host` go BEFORE the container (as in the docker CLI); everything after the container is the command, flags included, taken from the raw line and split like a shell line: `docker exec web ls -la /`, `docker exec -u root web sh -c "echo a; exit 3"`. Output: stdout, then stderr (warning); the command's exit code |
154
+ | `docker images`, `docker images prune [--all] [--yes]` | read; admin | |
155
+ | `docker pull <image>` | manage | progress until done |
156
+ | `docker rmi <image...> [--force] [--yes]` | admin | asks first |
157
+ | `docker stacks`, `stacks show <name>` | read | the compose file is shown when it can be read; a folder with a compose file and no containers is listed as `down` |
158
+ | `docker stacks start\|stop\|restart\|pull <name>` | manage | |
159
+ | `docker stacks up <name> [--file <path>] [--pull]` | admin | compose up; a progress block labelled with the last output line, the log as a code block when it fails |
160
+ | `docker stacks down <name> [--volumes] [--yes]` | admin | asks first |
161
+ | `docker stacks rm <name> [--yes]` | admin | deletes the compose file of a stack that is down; asks first |
162
+ | `docker compose ...` | | `compose` is an alias of `stacks` (`docker compose up shop`) |
163
+ | `docker volumes`, `volumes inspect <name>` | read | |
164
+ | `docker volumes create <name> [--driver <d>]`, `rm <name...> [--force] [--yes]`, `prune [--yes]` | admin | |
165
+ | `docker networks`, `networks inspect <name>` | read | |
166
+ | `docker networks create <name> [--driver <d>] [--internal] [--subnet <cidr>]`, `rm <name...> [--yes]`, `prune [--yes]` | admin | |
167
+ | `docker system info`, `system df`, `system events [--since <1h>] [--follow]` | read | |
168
+
169
+ ## Compose
170
+
171
+ Stacks can be created, updated and removed from their compose file. This runs the `docker compose` CLI on the machine
172
+ the server runs on (the Engine API cannot do it), so **the CLI must be installed there**, for example in the server's own
173
+ container image, and the files must be under `composeRoots`: no root, no compose feature (every route answers 409 with the
174
+ text of `GET /compose`).
175
+
176
+ - Settings: `composeRoots` (the only folders files are read from, written to and run from; absolute paths only),
177
+ `composeCommand` (default `docker compose`; `docker-compose` works, except on a TLS host) and `composeTimeoutSeconds` (900).
178
+ - Compose runs on the server's machine and **resolves `env_file`, build contexts, file secrets and `include`s on the server's disk**
179
+ (and sends them to the engine), so compose is on for the host `local` only unless `composeHosts` lists more hosts.
180
+ - The file of stack `<name>` is the first of: the stack's `com.docker.compose.project.config_files` label (when the host is
181
+ a unix socket and it passes the checks of the roots), `<root>/<name>/compose.yaml`, `compose.yml`, `docker-compose.yml`,
182
+ `docker-compose.yaml` (the folder `<root>/<name>` must be a real folder directly under the root, not a link). Every path is
183
+ checked the same way: absolute, `.yml`/`.yaml`, real path under a root, regular file, at most 256 KB. A folder directly
184
+ under a root with one of those files and a valid name (`^[a-z0-9][a-z0-9_-]{0,62}$`) is a stack even without containers:
185
+ it is listed with the state `down` (at most 200 folders per root); a project that has containers, hidden ones too, is never
186
+ `down`, and a project whose containers are all hidden does not exist (`GET /stacks/<name>` is 404).
187
+ - `PUT .../compose` checks the content with `<composeCommand> --project-name=<name> --file=<temp file in the same folder> config --quiet`
188
+ (a failure is 400 with compose's message, the temp file's path replaced by `compose.yaml`; nothing changes), then renames
189
+ the temp file over the target: the existing file (it keeps the file's mode; a new file is 0644), or
190
+ `<first existing root>/<name>/compose.yaml` (the folder is created, and removed again when the write fails). The target and
191
+ its folder are never links.
192
+ - `POST .../up` is an operation of kind `stack-up` (`--project-name=<name> --file=<real path> up -d --remove-orphans`,
193
+ `--pull always` with `pull`, in the file's folder, killed at `composeTimeoutSeconds`). `file` only serves a stack with no
194
+ file by the rule. Its `log` holds the last 200 lines of the CLI's output (stdout and stderr merged, ANSI codes stripped,
195
+ lines cut at 2000 characters); `message` is the last line. The `log` and `message` of a `stack-up` are shown only to
196
+ `docker:admin` (`GET /operations`, `GET /operations/{id}` and the `docker:operation` event, personalised per socket; the
197
+ others get `log: []` and no `message`), because compose output can quote values. One stack has at most one running `up`
198
+ (409), it counts towards the 5 running operations, and `down`, a write and a delete of that stack are 409
199
+ `stack <name> is already being updated` meanwhile. At most 5 other compose processes (checks, `down`) run at once.
200
+ `down` with a file is `compose down` (`--volumes` with `volumes`), 120 s, 504 on timeout; `volumes` without a file is 400
201
+ `volumes needs a compose file`.
202
+ - The CLI is started without a shell from an argument list, with the host's connection always as docker's global flags, the
203
+ default socket included (`--host`, `--tlsverify --tlscacert --tlscert --tlskey`; `docker-compose` gets `DOCKER_HOST`), so a
204
+ docker context or `DOCKER_HOST` of the server can never pick another engine. Its environment is minimal: `PATH`, `HOME`,
205
+ `USER`, `LANG`, `TMPDIR`, the names in `composeEnv`, and `COMPOSE_INTERACTIVE_NO_CLI=1`, `COMPOSE_MENU=false`, `NO_COLOR=1`.
206
+ Its output is never interpreted, only shown. The running processes are killed (with their process group) at the time limit
207
+ and when the plugin stops. The audit of a failed write or `up` says `compose exited with code <n>`, never compose's message.
208
+ - `up` and compose `down` are refused (409) when the stack has a protected container (`container <name> is protected`) or
209
+ a hidden one (`stack <name> has containers this plugin may not change`). Changes are audited (`docker.stack.up`,
210
+ `docker.stack.down`, `docker.stack.compose.write`, `docker.stack.compose.remove`; the content is not recorded).
211
+ - The demo reads `QCLI_DOCKER_COMPOSE_ROOTS` (comma separated).
212
+
213
+ ## MCP tools
214
+
215
+ The commands are MCP tools like every command (with their permissions); besides them the provider `docker` offers
216
+ structured tools returning the REST shapes: `docker_list_containers`, `docker_inspect_container`, `docker_logs`,
217
+ `docker_stats`, `docker_list_images`, `docker_list_stacks`, `docker_system_info` (`docker:read`, read-only hint),
218
+ `docker_start`, `docker_stop`, `docker_restart` (`docker:manage`) and `docker_exec` (`docker:exec`, destructive hint).
219
+ The structured provider has no remove or prune tool.
220
+
221
+ ## Rules that hold for routes, commands, the socket and MCP alike
222
+
223
+ - Sign-in: the Docker socket is root-equivalent, so unless `allowUnprotected` is on a call without a signed-in caller (a
224
+ server that is not protected) is refused everywhere: routes 403 `the Docker plugin needs a protected server (sign-in);
225
+ see its allowUnprotected setting`, commands the same text after `Error: `, MCP tools the same error, the exec socket
226
+ closes 4401 `login required`. The check is one method of the service, `assert_caller`, called once per call.
227
+ - `readOnly` refuses every change, including exec. Hidden containers do not exist. Protected containers can be read but
228
+ not changed (actions, rm, exec, prune, stack actions on them).
229
+ - Every change is recorded in the server's audit log when it has one: event `docker.<object>.<action>`
230
+ (`docker.container.restart`, `docker.image.pull`, `docker.exec.run`, `docker.exec.session`, `docker.stack.down`,
231
+ `docker.volumes.prune`, ...), `target` `docker:<host>/<kind>/<name>`, `properties` `{ host, ... }`; the command of an exec
232
+ is recorded, its output is not; failures carry `properties.error`, and so do changes refused by read-only mode or
233
+ protection (hidden containers do not exist, so they leave no entry).
234
+ - A protected container, running or not, refuses `stacks down` of its stack whole; with hidden containers in the stack,
235
+ `stacks down` leaves them and the stack's networks alone. `networks prune` is done by the plugin (not the engine's
236
+ prune): it removes the unused custom networks and leaves those a hidden or protected container is attached to.
237
+ - Hidden containers also stay out of events: an event of another type that names one in its attributes is dropped.
238
+ - The exec socket's `exit` message carries the exec's real exit code; the exec of a client that leaves while the session
239
+ starts is ended. An open exec session ends (close 4401 `permission removed`) when its user loses `docker:exec`, and with 4401
240
+ `session ended` when its session ends (logout, revoke, expiry, user disabled); re-checked on every change and every 30 s
241
+ like the shell socket.
242
+ - A stack's compose file is the first of the label `com.docker.compose.project.config_files` (only on a unix socket host and
243
+ only when it passes the checks of `composeRoots`) and the file of the root's sub-folder (see Compose). The label is
244
+ written by whoever created the container, so it is never trusted; anything that fails a check is `composeFile: null`.
245
+ - Cross-site: with `allowUnprotected`, a change by a caller without a principal (any route but GET, HEAD and OPTIONS, and the exec socket) that carries an `Origin` whose host:port differs from the request's `Host` is refused: 403 / close 4403 `cross-site requests are refused` (an absent Origin passes, `null` counts as cross-site). A principal always needs `docker:exec` on the exec socket, also on a server that is not protected.
246
+ - The `log` and `message` of a `stack-up` go to `docker:admin`, and to a caller without a principal only with `allowUnprotected`.
247
+ - A timed-out one-off exec (`504`) may keep running in the container: the Engine API cannot kill an exec.
248
+ - Pulls: at most 5 run at once (`409 too many operations are running (5 at most)`); a pull whose connection drops or that
249
+ receives nothing for 120 s fails. `GET /stats` takes at most 100 ids (`400 too many ids (100 at most)`) and samples at
250
+ most 10 containers at a time. A log line longer than 16 KB is cut and ends with `…`.
251
+ - Error texts never contain file-system paths of TLS files: an unreadable one is `cannot read the TLS files of <host>`.
252
+ - Nothing the plugin answers contains TLS key paths, registry credentials or unmasked secret-like environment values
253
+ (names containing password, passwd, secret, token, key, credential or auth show `••••••`).
254
+
255
+ ## Console page
256
+
257
+ The page is the Console module `@qodalis/console-module-docker` (group Operations, `docker:read`, with an Overview card),
258
+ embedded into the wheel by `scripts/copy_console.py` and served at `/qcli/modules/docker`; `set_console_dir(False)` leaves
259
+ it out (as does a build without the module: the plugin works without the page).
260
+
261
+ ## Engine client
262
+
263
+ The plugin talks to the Engine API with a small HTTP/1.1 client on `asyncio` streams (unix socket, TCP, TLS; chunked
264
+ streams and the connection upgrade of an exec), not with `aiodocker` or `httpx`: it has no dependency besides FastAPI, and
265
+ the streams it needs (logs, events, pulls, a hijacked exec) are controlled byte by byte.
266
+
267
+ ## Tests
268
+
269
+ `tests/test_docker_*.py` of the server run against a fake Engine API (`tests/docker_fake_engine.py`) fed from
270
+ `fixtures/engine/*.json`; `fixtures/README.md` says which engine request maps to which file. The expected `/execute`
271
+ answers (`fixtures/expected/commands.v2.jsonl`, `commands.v1.jsonl`) and REST answers (`fixtures/expected/rest/*.json`)
272
+ are copied from the Node server (its generator writes them); the Python tests (`tests/test_docker_expected.py`) must
273
+ produce the same, byte for byte for the commands.