Skip to main content

Image

c.Image calls the API's Image group. The Docker images of the host.

Methods​

MethodReturnsPermissionDescription
List(ctx, hostname)*Response[Collection[ImageEntry]]image:readList the images of the host.
Pull(ctx, hostname, input)*Response[Collection[ImagePullResult]]image:executePull an image.
Delete(ctx, hostname, input)*Response[Collection[ImageResult]]image:writeRemove an image.

List​

func (s *ImageService) List(
ctx context.Context,
hostname string,
) (*Response[Collection[ImageEntry]], error)

List the images of the host.

Reads each image through gohai's docker collector, which runs docker images. A host whose docker does not answer reports skipped.

It sends GET /api/node/{hostname}/image, and needs the permission image:read.

The examples of the method's definition:

A host with an image, go run image.go list:

resp, err := c.Image.List(ctx, target)

Pull​

func (s *ImageService) Pull(
ctx context.Context,
hostname string,
input ImagePullInput,
) (*Response[Collection[ImagePullResult]], error)

Pull an image.

Runs docker pull, and answers the ID and the size of the image that the host has after it. A pull that gets nothing new, because the host had the image of that reference already, reports changed: false.

It sends POST /api/node/{hostname}/image/pull, and needs the permission image:execute.

The examples of the method's definition:

Pull an image, go run image.go pull:

resp, err := c.Image.Pull(ctx, target, client.ImagePullInput{Image: "alpine:3.20"})

Delete​

func (s *ImageService) Delete(
ctx context.Context,
hostname string,
input ImageDeleteInput,
) (*Response[Collection[ImageResult]], error)

Remove an image.

Runs docker rmi, with -f when force is set, which removes an image that a container uses. An image that the host does not have reports changed: false.

It sends DELETE /api/node/{hostname}/image/{image}, and needs the permission image:write.

The examples of the method's definition:

Remove an image, go run image.go delete:

resp, err := c.Image.Delete(ctx, target, client.ImageDeleteInput{Image: "alpine:3.20"})

Types​

The fields of each type are the properties of its schema in the API's spec.

ImageDeleteInput​

FieldTypeDescription
ImagestringThe image of the path. The image, by its reference or its ID.
ForceboolRemove it also when a container uses it.

ImageEntry​

FieldTypeDescription
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
IDstringThe image's ID.
RepositorystringIts repository, such as alpine.
SizestringIts size, as docker prints it, such as 7.8MB.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.
TagstringIts tag, such as 3.20.

ImagePullInput​

FieldTypeDescription
ImagestringThe image, such as alpine:3.20.

ImagePullResult​

FieldTypeDescription
ChangedboolWhether the pull got a new image: false when the host had it already.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
ImagestringThe image.
ImageIDstringThe ID of the image that the host has now.
Sizeint64Its size in bytes.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

ImageResult​

FieldTypeDescription
ChangedboolWhether the host changed.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
ImagestringThe image.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

RowStatus​

What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

A string, one of ok, failed, skipped, timeout.

Example​

examples/sdk/client/image.go runs each example of this page. With no argument, it lists them.