title: sam-cli local invoke error: Docker timeout after few seconds
body: <p>I'm working on macOS High Sierra, and trying to run sam-cli to debug my lambdas locally. Lambda runtime is nodejs8.10, SAM CLI, version 0.4.0</p>
  
  <p>I use the following command </p>
  
  <p><code>sam local invoke --event payload.json --debug-port 5858 [lambdaName] --profile [profileName]</code> </p>
  
  <p>The debugger gets invoked and i'm able to debug the lambda code for a while before the docker timeout occurs.</p>
  
  <pre><code>`Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/2.7/bin/sam", line 11, in &lt;module&gt;
      load_entry_point('aws-sam-cli==0.4.0', 'console_scripts', 'sam')()
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 722, in __call__
      return self.main(*args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 697, in main
      rv = self.invoke(ctx)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 895, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 535, in invoke
      return callback(*args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/decorators.py", line 64, in new_func
      return ctx.invoke(f, obj, *args[1:], **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/click/core.py", line 535, in invoke
      return callback(*args, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/samcli/commands/local/invoke/cli.py", line 44, in cli
      docker_network, log_file, skip_pull_image, profile)  # pragma: no cover
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/samcli/commands/local/invoke/cli.py", line 76, in do_cli
      stderr=context.stderr)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/samcli/commands/local/lib/local_lambda.py", line 80, in invoke
      stdout=stdout, stderr=stderr)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/samcli/local/lambdafn/runtime.py", line 98, in invoke
      container.wait_for_logs(stdout=stdout, stderr=stderr)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/samcli/local/docker/container.py", line 187, in wait_for_logs
      self._write_container_output(logs_itr, stdout=stdout, stderr=stderr)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/samcli/local/docker/container.py", line 206, in _write_container_output
      for frame_type, data in output_itr:
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/samcli/local/docker/attach_api.py", line 98, in _read_socket
      payload_type, payload_size = _read_header(socket)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/samcli/local/docker/attach_api.py", line 170, in _read_header
      data = read_exactly(socket, 8)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docker/utils/socket.py", line 47, in read_exactly
      next_data = read(socket, n - len(data))
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docker/utils/socket.py", line 31, in read
      return socket.recv(n)
  socket.timeout: timed out`
  </code></pre>
  
  <p>This is my sam template</p>
  
  <pre><code>`AWSTemplateFormatVersion: '2010-09-09'
  Transform: AWS::Serverless-2016-10-31
  Description: &gt;
      lambda Description
  
  # More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
  Globals:
      Function:
          Timeout: 300
  
  Resources:
      LambdaName:
          Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
          Properties:
              Handler: index.handler
              Runtime: nodejs8.10
              Environment:
                  Variables:
                      NODE_TLS_REJECT_UNAUTHORIZED : "0"
                      BUCKET_NAME : "bucketName"
                      KEY_NAME : "file.json"
                      DYNAMO_RULE_TABLE : "TableName"
                  NODE_ENV: "development" # NODE_ENV: "production"`
  </code></pre>
  
  <p>I'm unable to find the root cause for this issue.</p>