Sha256: 7c888c3e9a0537d941ad29dce35f9be94d0fc4dafe707148790546f569d71a0e

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# This class represents a Docker Container. It's important to note that nothing
# is cached so that the information is always up to date.
class Docker::Container
  include Docker::Model

  set_resource_prefix '/containers'

  set_create_request do |body|
    response = connection.post('/containers/create', nil, :body => body.to_json)
    @id = Docker::Util.parse_json(response)['Id']
    self
  end

  # Get more information about the Container.
  request :get, :json
  # Wait for the current command to finish executing.
  request :post, :wait
  # Start the Container.
  request :post, :start
  # Inspect the Container's changes to the filesysetem
  request :get, :changes
  # Stop the Container.
  request :post, :stop
  # Kill the Container.
  request :post, :kill
  # Restart the Container
  request :post, :restart

  # Export the Container as a tar.
  def export(&block)
    connection.get("/containers/#{id}/export", nil, :response_block => block)
    true
  end

  # Attach to a container's standard streams / logs.
  def attach(options = {})
    options = { :stream => true, :stdout => true }.merge(options)
    connection.post("/containers/#{id}/attach", options)
  end

  # Create an Image from a Container's change.s
  def commit(options = {})
    options.merge!('container' => self.id[0..7])
    hash = JSON.parse(connection.request(:post, '/commit', options))
    Docker::Image.send(:new, :id => hash['Id'], :connection => self.connection)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
docker-api-1.1.1 lib/docker/container.rb