Class: Docker::API::ExecResult

Inherits:
Struct
  • Object
show all
Defined in:
lib/docker/api/resources/exec.rb

Overview

What a command run inside a container produced.

A non-zero #exit_code is returned rather than raised. Whether a failing command is an error depends entirely on why it was run -- a test runner expects failures, a provisioning step does not -- so the decision belongs to the caller. #success? and #check! are there for the common cases.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exit_codeObject

Returns the value of attribute exit_code

Returns:

  • (Object)

    the current value of exit_code



14
15
16
# File 'lib/docker/api/resources/exec.rb', line 14

def exit_code
  @exit_code
end

#stderrObject

Returns the value of attribute stderr

Returns:

  • (Object)

    the current value of stderr



14
15
16
# File 'lib/docker/api/resources/exec.rb', line 14

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout

Returns:

  • (Object)

    the current value of stdout



14
15
16
# File 'lib/docker/api/resources/exec.rb', line 14

def stdout
  @stdout
end

Instance Method Details

#check!self

Returns:

  • (self)

Raises:

  • (Docker::API::Error)

    if the command exited non-zero, or if the daemon did not report an exit code at all



27
28
29
30
31
# File 'lib/docker/api/resources/exec.rb', line 27

def check!
  return self if success?

  raise Error.new(check_message, operation: "exec")
end

#outputString

Returns stdout and stderr in the order they were produced.

Returns:

  • (String)

    stdout and stderr in the order they were produced



34
35
36
# File 'lib/docker/api/resources/exec.rb', line 34

def output
  "#{stdout}#{stderr}"
end

#success?Boolean

Nil is not success. The daemon reports a null exit code while an exec is still being reaped, and treating that as zero fails open on exactly the question this struct exists to answer.

Returns:

  • (Boolean)

    whether the command exited zero



20
21
22
# File 'lib/docker/api/resources/exec.rb', line 20

def success?
  exit_code == 0
end