nekomata / docker /image.lisp
SNAPKITTYWEST's picture
push from SNAPKITTYWEST/nekomata
3b70664 verified
Raw History Blame Contribute Delete
2.72 kB
(in-package #:nekod.docker)
(defun pull-image (sock name &optional (tag "latest"))
"Pull a Docker image from a registry.
name β€” image name, e.g. \"nginx\" or \"registry.example.com/myapp\"
tag β€” image tag, defaults to \"latest\"
Returns the event stream body as a string."
(docker-post sock (format nil "/images/create?fromImage=~a&tag=~a" name tag)))
(defun list-images (sock &optional (all nil))
"List locally available Docker images.
all=t includes intermediate images.
Returns JSON body as a string."
(multiple-value-bind (status body)
(docker-get sock (format nil "/images/json?all=~a" (if all 1 0)))
(if (= status 200) body
(error 'nekod:docker-api-error :message body :status-code status
:endpoint "/images/json"))))
(defun inspect-image (sock id)
"Inspect a Docker image by ID or name. Returns full JSON metadata as a string."
(multiple-value-bind (status body)
(docker-get sock (format nil "/images/~a/json" id))
(if (= status 200) body
(error 'nekod:docker-api-error :message body :status-code status
:endpoint (format nil "/images/~a/json" id)))))
(defun remove-image (sock id &optional (force nil) (no-prune nil))
"Remove a Docker image by ID or name.
force β€” force removal even if the image is in use
no-prune β€” do not delete untagged parent images
Returns JSON body on success."
(multiple-value-bind (status body)
(docker-delete sock (format nil "/images/~a?force=~a&noprune=~a"
id
(if force "true" "false")
(if no-prune "true" "false")))
(if (member status '(200 204)) body
(error 'nekod:docker-api-error :message body :status-code status
:endpoint (format nil "/images/~a" id)))))
(defun tag-image (sock id repo tag)
"Re-tag a Docker image.
id β€” source image ID or name
repo β€” target repository name
tag β€” target tag
Returns t on success."
(multiple-value-bind (status body)
(docker-post sock (format nil "/images/~a/tag?repo=~a&tag=~a" id repo tag))
(if (= status 201) t
(error 'nekod:docker-api-error :message body :status-code status
:endpoint (format nil "/images/~a/tag" id)))))
(defun prune-images (sock)
"Remove all dangling (untagged, unreferenced) images.
Returns JSON summary as a string."
(multiple-value-bind (status body)
(docker-post sock "/images/prune")
(if (= status 200) body
(error 'nekod:docker-api-error :message body :status-code status
:endpoint "/images/prune"))))