Method: Docker::Container#exec

Defined in:
lib/docker/container.rb

#exec(command, options = {}, &block) ⇒ Docker::Exec

Create an Exec instance inside the container

Parameters:

  • command (String, Array)

    The command to run inside the Exec instance

  • options (Hash) (defaults to: {})

    The options to pass to Docker::Exec

Returns:



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
85
86
87
88
89
90
91
92
93
94
# File 'lib/docker/container.rb', line 55

def exec(command, options = {}, &block)
  # Establish values
  tty = options.delete(:tty) || false
  detach = options.delete(:detach) || false
  user = options.delete(:user)
  stdin = options.delete(:stdin)
  stdout = options.delete(:stdout) || !detach
  stderr = options.delete(:stderr) || !detach
  wait = options.delete(:wait)

  opts = {
    'Container' => self.id,
    'User' => user,
    'AttachStdin' => !!stdin,
    'AttachStdout' => stdout,
    'AttachStderr' => stderr,
    'Tty' => tty,
    'Cmd' => command
  }.merge(options)

  # Create Exec Instance
  instance = Docker::Exec.create(
    opts,
    self.connection
  )

  start_opts = {
    :tty => tty,
    :stdin => stdin,
    :detach => detach,
    :wait => wait
  }

  if detach
    instance.start!(start_opts)
    return instance
  else
    instance.start!(start_opts, &block)
  end
end