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 27 28 29 30 31 32 33 |
# File 'lib/docker/exec.rb', line 20 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
37 38 39 |
# File 'lib/docker/exec.rb', line 37 def json Docker::Util.parse_json(connection.get(path_for(:json), {})) end |
#resize(query = {}) ⇒ Docker::Exec
Resize the TTY associated with the Exec instance
99 100 101 102 |
# File 'lib/docker/exec.rb', line 99 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.
52 53 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 |
# File 'lib/docker/exec.rb', line 52 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
8 9 10 |
# File 'lib/docker/exec.rb', line 8 def to_s "Docker::Exec { :id => #{self.id}, :connection => #{self.connection} }" end |