# 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