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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/docker/exec.rb', line 22 def self.create( = {}, conn = Docker.connection) container = .delete('Container') # Podman does not attach these by default but does require them to be attached if ::Docker.podman?(conn) ['AttachStderr'] = true if ['AttachStderr'].nil? ['AttachStdout'] = true if ['AttachStdout'].nil? end resp = conn.post("/containers/#{container}/exec", {}, body: MultiJson.dump()) hash = Docker::Util.parse_json(resp) || {} new(conn, hash) end |
Instance Method Details
#json ⇒ Object
Get info about the Exec instance
39 40 41 |
# File 'lib/docker/exec.rb', line 39 def json Docker::Util.parse_json(connection.get(path_for(:json), {})) end |
#resize(query = {}) ⇒ Docker::Exec
Resize the TTY associated with the Exec instance
101 102 103 104 |
# File 'lib/docker/exec.rb', line 101 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.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/docker/exec.rb', line 54 def start!( = {}, &block) # Parse the Options tty = !!.delete(:tty) detached = !!.delete(:detach) stdin = [:stdin] read_timeout = [:wait] # Create API Request Body body = MultiJson.dump( 'Tty' => tty, 'Detach' => detached ) excon_params = { body: body } 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
10 11 12 |
# File 'lib/docker/exec.rb', line 10 def to_s "Docker::Exec { :id => #{self.id}, :connection => #{self.connection} }" end |