Class: Docker::Exec
Overview
This class represents a Docker Exec Instance.
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
-
.create(options = {}, conn = Docker.connection) ⇒ Docker::Exec
Create a new Exec instance in a running container.
Instance Method Summary collapse
-
#json ⇒ Object
Get info about the Exec instance.
-
#resize(query = {}) ⇒ Docker::Exec
Resize the TTY associated with the Exec instance.
-
#start!(options = {}, &block) ⇒ Array, Int
Start the Exec instance.
-
#to_s ⇒ String
Convert details about the object into a string.
Methods included from Base
Class Method Details
.create(options = {}, conn = Docker.connection) ⇒ Docker::Exec
Create a new Exec instance in a running container. Please note, this does NOT execute the instance - you must run #start. Also, each instance is one-time use only.
20 21 22 23 24 25 26 |
# File 'lib/docker/exec.rb', line 20 def self.create( = {}, conn = Docker.connection) container = .delete('Container') resp = conn.post("/containers/#{container}/exec", {}, :body => .to_json) hash = Docker::Util.parse_json(resp) || {} new(conn, hash) end |
Instance Method Details
#json ⇒ Object
Get info about the Exec instance
30 31 32 |
# File 'lib/docker/exec.rb', line 30 def json Docker::Util.parse_json(connection.get(path_for(:json), {})) end |
#resize(query = {}) ⇒ Docker::Exec
Resize the TTY associated with the Exec instance
92 93 94 95 |
# File 'lib/docker/exec.rb', line 92 def resize(query = {}) connection.post(path_for(:resize), query) self end |
#start!(options = {}, &block) ⇒ Array, Int
Start the Exec instance. The Exec instance is deleted after this so this command can only be run once.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/docker/exec.rb', line 45 def start!( = {}, &block) # Parse the Options tty = !!.delete(:tty) detached = !!.delete(:detach) stdin = [:stdin] read_timeout = [:wait] # Create API Request Body body = { "Tty" => tty, "Detach" => detached } excon_params = { :body => body.to_json } msgs = Docker::Messages.new unless detached if stdin excon_params[:hijack_block] = Docker::Util.hijack_for(stdin, block, msgs, tty) else excon_params[:response_block] = Docker::Util.attach_for(block, msgs, tty) end end excon_params[:read_timeout] = read_timeout unless read_timeout.nil? connection.post(path_for(:start), nil, excon_params) [msgs., msgs., self.json['ExitCode']] end |
#to_s ⇒ String
Convert details about the object into a string
8 9 10 |
# File 'lib/docker/exec.rb', line 8 def to_s "Docker::Exec { :id => #{self.id}, :connection => #{self.connection} }" end |