Class: Docker::Container
- Inherits:
-
Object
- Object
- Docker::Container
- Defined in:
- lib/docker/container.rb
Overview
This class represents a Docker Container. It’s important to note that nothing is cached so that the information is always up to date.
Instance Attribute Summary
Attributes included from Model
Instance Method Summary collapse
-
#attach(options = {}, &block) ⇒ Object
Attach to a container’s standard streams / logs.
-
#commit(options = {}) ⇒ Object
Create an Image from a Container’s change.s.
-
#export(&block) ⇒ Object
Export the Container as a tar.
-
#run(cmd, time = 1000) ⇒ Object
Given a command and an optional number of seconds to wait for the currently executing command, creates a new Container to run the specified command.
-
#wait(time = 60) ⇒ Object
Wait for the current command to finish executing.
Methods included from Model
Instance Method Details
#attach(options = {}, &block) ⇒ Object
Attach to a container’s standard streams / logs.
61 62 63 64 65 |
# File 'lib/docker/container.rb', line 61 def attach( = {}, &block) = { :stream => true, :stdout => true }.merge() connection.post("/containers/#{id}/attach", , :response_block => block) end |
#commit(options = {}) ⇒ Object
Create an Image from a Container’s change.s
68 69 70 71 72 |
# File 'lib/docker/container.rb', line 68 def commit( = {}) .merge!('container' => self.id[0..7]) hash = Docker::Util.parse_json(connection.post('/commit', )) Docker::Image.send(:new, :id => hash['Id'], :connection => self.connection) end |
#export(&block) ⇒ Object
Export the Container as a tar.
55 56 57 58 |
# File 'lib/docker/container.rb', line 55 def export(&block) connection.get("/containers/#{id}/export", nil, :response_block => block) true end |
#run(cmd, time = 1000) ⇒ Object
Given a command and an optional number of seconds to wait for the currently executing command, creates a new Container to run the specified command. If the command that is currently executing does not return a 0 status code, an UnexpectedResponseError is raised.
46 47 48 49 50 51 52 |
# File 'lib/docker/container.rb', line 46 def run(cmd, time = 1000) if (code = tap(&:start?).wait(time)['StatusCode']).zero? commit.run(cmd).tap(&:start?) else raise UnexpectedResponseError, "Command returned status code #{code}." end end |
#wait(time = 60) ⇒ Object
Wait for the current command to finish executing.
37 38 39 40 |
# File 'lib/docker/container.rb', line 37 def wait(time = 60) resp = connection.post("/containers/#{id}/wait", nil, :read_timeout => time) Docker::Util.parse_json(resp) end |