Class: Docker::Image
- Inherits:
-
Object
- Object
- Docker::Image
- Defined in:
- lib/docker/image.rb
Overview
This class represents a Docker Image.
Instance Attribute Summary
Attributes included from Model
Class Method Summary collapse
-
.build(commands, connection = Docker.connection) ⇒ Object
Given a Dockerfile as a string, builds an Image.
-
.search(query = {}, connection = Docker.connection) ⇒ Object
Given a query like ‘{ :term => ’sshd’ }‘, queries the Docker Registry for a corresponiding Image.
Instance Method Summary collapse
-
#create_from_file(file, options = {}) ⇒ Object
Given a Docker export and optional Hash of options, creates a new Image.
-
#insert(query = {}) ⇒ Object
Insert a file into the Image, returns a new Image that has that file.
-
#push(options = {}) ⇒ Object
Push the Image to the Docker registry.
-
#remove ⇒ Object
Remove the Image from the server.
Methods included from Multipart
Methods included from Model
#create!, #created?, included, #initialize, #to_s
Class Method Details
.build(commands, connection = Docker.connection) ⇒ Object
Given a Dockerfile as a string, builds an Image.
88 89 90 91 92 93 94 95 96 |
# File 'lib/docker/image.rb', line 88 def build(commands, connection = Docker.connection) body = multipart_request( '/build', 'Dockerfile', StringIO.new("#{commands}\n"), connection ) new(:id => extract_id(body), :connection => connection) end |
.search(query = {}, connection = Docker.connection) ⇒ Object
Given a query like ‘{ :term => ’sshd’ }‘, queries the Docker Registry for a corresponiding Image.
82 83 84 85 |
# File 'lib/docker/image.rb', line 82 def search(query = {}, connection = Docker.connection) hashes = connection.json_request(:get, '/images/search', query) || [] hashes.map { |hash| new(:id => hash['Name'], :connection => connection) } end |
Instance Method Details
#create_from_file(file, options = {}) ⇒ Object
Given a Docker export and optional Hash of options, creates a new Image.
69 70 71 72 73 74 |
# File 'lib/docker/image.rb', line 69 def create_from_file(file, = {}) File.open(file, 'r') do |f| read_chunked = lambda { f.read(Excon.defaults[:chunk_size]).to_s } self.create!(, :request_block => read_chunked) end end |
#insert(query = {}) ⇒ Object
Insert a file into the Image, returns a new Image that has that file.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/docker/image.rb', line 44 def insert(query = {}) ensure_created! body = self.connection.post( :path => "/images/#{self.id}/insert", :headers => { 'Content-Type' => 'text/plain', 'User-Agent' => "Docker-Client/1.2" }, :query => query, :expects => (200..204) ).body if (id = body.match(/{"Id":"([a-f0-9]+)"}\z/)).nil? || id[1].empty? raise UnexpectedResponseError, "Could not find Id in '#{body}'" else Docker::Image.new(:id => id[1], :connection => self.connection) end end |
#push(options = {}) ⇒ Object
Push the Image to the Docker registry.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/docker/image.rb', line 30 def push( = {}) ensure_created! self.connection.post( :path => "/images/#{self.id}/push", :headers => { 'Content-Type' => 'text/plain', 'User-Agent' => "Docker-Client/1.2" }, :query => , :body => Docker.creds, :expects => (200..204) ) true end |
#remove ⇒ Object
Remove the Image from the server.
61 62 63 64 65 66 |
# File 'lib/docker/image.rb', line 61 def remove ensure_created! self.connection.json_request(:delete, "/images/#{self.id}", nil) self.id = nil true end |