File size: 2,723 Bytes
3b70664 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | (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"))))
|