api: list Docker image details and delete images

GET /computes/{compute_id}/docker/images now returns the daemon image
id, size and creation date in addition to the tag, so a UI can show
and compare images instead of bare names. The fields are optional to
keep the response compatible with older computes.

Add DELETE /computes/{compute_id}/docker/images/{image} which removes
the image from the compute Docker daemon. The image name is passed as
a path so names with a slash or a tag separator work. A daemon that
refuses because a container uses the image answers a conflict; the
force query parameter removes it anyway.

The compute also drops the controller digest to local id translation
recorded when the image was synced, since it no longer matches
anything on the daemon.
This commit is contained in:
YueGuobin committed 2026-11-06 14:22:22 +08:00
1 parent 4c00d223e4
commit c1e03194d3
7 files changed
+145 -7

No files matched your search

+16
View File
@@ -73,6 +73,22 @@ async def load_docker_image(
await docker_manager.load_image(request.stream(), image=image, digest=digest)
@router.delete("/docker/images/{image:path}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_docker_image(
image: str,
force: bool = Query(False, description="Remove the image even if a container uses it"),
) -> None:
"""
Delete a Docker image from the Docker daemon.
The daemon refuses to delete an image used by a container (even a stopped
one) and answers a conflict, unless force is set.
"""
docker_manager = Docker.instance()
await docker_manager.delete_image(urllib.parse.unquote(image), force=force)
@router.get("/dynamips/images")
async def get_dynamips_images() -> List[dict]:
"""
@@ -247,6 +247,29 @@ async def docker_load_image(compute_id: Union[str, UUID], request: Request) -> N
await compute.http_query("POST", "/docker/images/load", data=request.stream(), timeout=None)
@router.delete(
"/{compute_id}/docker/images/{image:path}",
status_code=status.HTTP_204_NO_CONTENT,
dependencies=[Depends(has_privilege("Compute.Modify"))],
)
async def docker_delete_image(
compute_id: Union[str, UUID],
image: str,
force: bool = Query(False, description="Remove the image even if a container uses it"),
) -> None:
"""
Delete a Docker image on a compute.
The compute refuses to delete an image used by a container (even a stopped
one) and answers a conflict, unless force is set.
Required privilege: Compute.Modify
"""
compute = Controller.instance().get_compute(str(compute_id))
await compute.http_query("DELETE", f"/docker/images/{image}", params={"force": str(force).lower()})
@router.get("/{compute_id}/virtualbox/vms", response_model=List[schemas.ComputeVirtualBoxVM])
async def virtualbox_vms(compute_id: Union[str, UUID]) -> List[schemas.ComputeVirtualBoxVM]:
"""