Repository navigation
Closed
Labels
priority/p2-mediumPriority P2: standard workscope/cliCore CLI framework, Typer subcommands, options, and tablestype/bugType bug: the code does not do what it must
Description
Problem
Lines cited at dcafadf. No cited line has moved at 132ecc5. Paths are under src/devops_cli/ unless they start with tests/ or docs/. Paths marked docker-py are in the locked docker 7.2.0 (pyproject.toml:24).
devops docker prune fails on every engine, Docker and Podman alike:
- After the confirmation, it calls
client.system.prune(volumes=volumes)(commands/docker.py:200-201). - docker-py 7.2.0's
DockerClienthas nosystemattribute. Checked in the locked environment, its public attributes areconfigs,containers,df,events,from_context,from_env,images,info,login,networks,nodes,ping,plugins,secrets,services,swarm,versionandvolumes. - So the command ends in an
AttributeErrortraceback before it sends any request. The call dates from v0.1.8.
The tests do not catch this:
- The client in both prune tests is a bare
MagicMock, which accepts any attribute (tests/test_docker.py:34,:42,:210,:218). - One test pins a tuple return value (
:218), and the command parses that tuple (commands/docker.py:202-203). No docker-py prune call returns a tuple.
The docs describe a different command:
- The cheatsheet maps it to
docker system prune -af --volumesand says it deletes "dangling images and cache" (docs/cheatsheets/docker.md:24). - The knowledge base shows
devops docker prune --all, a flag the command does not have, and says it cleans the build cache (ai/knowledge_base/it_domains/tools/docker.md:25-26).
docker-py already has the calls:
- Each collection has
prune(filters=None)(docker-pymodels/containers.py:1026,models/images.py:489,models/networks.py:216,models/volumes.py:97). - Each posts to the Engine API's
/containers/prune,/images/prune,/networks/pruneor/volumes/prune, and returns the reply as a dict. - The container, image and volume replies carry
SpaceReclaimed. The network reply lists only the deleted networks.
Acceptance criteria
- Prune calls.
devops docker prune --forcecallscontainers.prune(),networks.prune()andimages.prune(), once each, in that order and with no filters.- With
--volumes, it then also callsvolumes.prune(). Without--volumes, it does not. - No request is sent before the confirmation;
--dry-runstill sends none.
- Reclaimed space.
- The success line (
MESSAGES.docker.pruned_success) reports the sum of theSpaceReclaimedvalues. A missing ornullvalue counts as 0. - Example: containers 5 MiB, images 5 MiB and a network reply without the key report "10 MB". With
--volumesand 1 MiB from volumes, the report is "11 MB". - The tuple branch (
commands/docker.py:202-203) is removed.
- The success line (
- Errors. A daemon error from any prune call (a mocked
docker.errors.APIError) ends the command with exit 1 and one error line that holds the daemon's text, with no traceback. - Specced test clients.
- A
docker_clientfixture intests/conftest.pyreturnscreate_autospec(docker.DockerClient, instance=True). - Its
containers,images,networksandvolumesarecreate_autospecof docker-py'sContainerCollection,ImageCollection,NetworkCollectionandVolumeCollection(instance=True). Itsapiiscreate_autospec(docker.APIClient, instance=True). - This matters because, checked in the locked environment,
create_autospecof the client alone leaves those properties as plainMagicMocks and has noapiat all, sinceapiis set in__init__. - A test pins the fixture:
client.systemraisesAttributeError, andclient.containers.prune(volumes=True)raisesTypeError. - Every Docker client mock in
tests/test_docker.pyuses the fixture, and the new prune tests do too.
- A
- No old call is left.
rg -n 'system\.prune' src testsprints nothing. - Help and docs.
- The command's help, its confirmation prompt and the
--volumeshelp say what is removed: stopped containers, unused networks, dangling images and, with--volumes, unused volumes. docs/commands/docker.mdis generated from that help text and is not edited by hand. It is regenerated withdevops docs generate, and the docs check passes.- The cheatsheet row maps the command to
docker system prune [--volumes]. It says the build cache is cleared bydevops docker cache --prune. - The knowledge-base lines show
devops docker prunewithout--alland no longer mention the build cache.
- The command's help, its confirmation prompt and the
- Release.
- Tests are offline and never build a real
DockerClient. The new tests take well under 1 s together, anduv run devops cipasses.
- Tests are offline and never build a real
- Pending a person: on the devcontainer's Docker engine, and on rootless Podman reached through
DOCKER_HOST, rundevops docker prune --forceanddevops docker prune --force --volumes. Before each run, create a stopped container, a dangling image, an unused network, an unused anonymous volume and an unused named volume. Record in the task file what was removed, whether the named volume and tagged images were kept, and the reported space.
Key questions
- Dangling images or all unused images? Proposed: dangling only.
images.prune()with no filter prunes only dangling images, asdocker system prunewithout-adoes.- So a prune never deletes a tagged base image that the next build needs.
- No
--allflag is added.
- What does
--volumesremove? Proposed: whatevervolumes.prune()with no filter removes.- On Docker (Engine API 1.42 and later) that is unused anonymous volumes only, as
docker system prune --volumesremoves. - Podman's behaviour is recorded by the person step. The help says "unused volumes", which is true on both engines whichever volumes Podman removes.
- No
allfilter is sent.
- On Docker (Engine API 1.42 and later) that is unused anonymous volumes only, as
- Does the prune also clear the build cache, as
docker system prunedoes? Proposed: no.devops docker cache --prunealready does that throughDockerEngineService.prune_build_cache(docker/engine.py:527-536).- On Podman there is no build-prune route, which feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117 handles.
- Where does the prune live? Proposed: in a
DockerEngineServicemethod next toprune_build_cache.- It wraps daemon errors in
DockerEngineErrorin the same way and returns the bytes reclaimed. - The command prints the error line and exits 1.
- It wraps daemon errors in
Strategic alignment
- Priority P2. It is a broken command on every engine with a contained fix and no security impact.
- Library first. It uses docker-py's own collection
prunecalls. There is no new dependency, and nothing is hand-written in their place. - Testing practice. Specced mocks make a call to a method that docker-py lacks fail in the suite, not on a user's machine.
- Size: small, one PR. It touches
commands/docker.py,docker/engine.py,lang/en/help.py,lang/en/messages.py,tests/conftest.py,tests/test_docker.pyand the docs named above. - Dependencies. None. It is independent of fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108, fix(security): a sandbox workspace can never expose the container engine socket or the user's runtime directory and its session bus #1115 and feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117.
- Proposed milestone: backlog (P2). A person plans it on the board.
- Related: feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117, which brings Podman endpoints. Its build-cache message on Podman points to this command, and its person step runs it.
Metadata
Metadata
Assignees
Labels
priority/p2-mediumPriority P2: standard workscope/cliCore CLI framework, Typer subcommands, options, and tablestype/bugType bug: the code does not do what it must
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Linked: #1316, #1108, #1117 and #1327.
devops docker prunecallsclient.system.prune(commands/docker.py:201), which the SDK lacks; #1316's Protocol must gain the prune calls, and #1327 ownstests/test_docker.py. Found by the 2026-10-08 backlog review.fix(cli): devops docker prune removes stopped containers, unused netw…