feat(images): add docker.images.pullthis reflects docker image pull
@@ -1,5 +1,5 @@
name: docker
-version: 0.4.0
+version: 0.4.1
crystal: ">= 0.36.1"
license: MIT
authors:
@@ -208,5 +208,5 @@ class Docker::Api::ApiClient
include Containers
include Daemon
include Images
- include ::Volumes
+ include Volumes
end
@@ -66,4 +66,16 @@ module Docker::Api::Images
response = get "/images/#{id}/json"
Models::Image.from_json response.body
end
+
+ # Pull an image from a registry.
+ #
+ # Identical to the `docker pull` command.
+ def pull_image(name : String, tag : String? = nil)
+ params = HTTP::Params.build do |param|
+ param.add "name", name
+ param.add "tag", tag.to_s unless tag.nil?
+ end
+ response = get "/images/create?#{params}"
+
+ end
end
@@ -5,7 +5,7 @@ module Docker::Api::Models
@[JSON::Field(key: "Id")]
getter id : String
@[JSON::Field(key: "Container")]
- getter container : String
+ getter container : String?
@[JSON::Field(key: "Comment")]
getter comment : String
@[JSON::Field(key: "Os")]
@@ -1,6 +1,6 @@
require "./response"
-module Docker::Api
+module Docker::Api::Models
struct Volume < Response
@[JSON::Field(key: "CreatedAt")]
getter created_at : String
@@ -58,4 +58,12 @@ class Docker::Images
image_ids = client.images(all, name, filters).map &.id
image_ids.map &->get(String)
end
+
+ # Pull an image from a registry.
+ def pull(image : String, tag : String? = nil)
+ parts = image.split(":")
+ name = parts.first
+ tag = parts.last if tag.nil?
+ client.pull_image(name, tag)
+ end
end