Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Error: Docker is not reachable (even though it is!) #4329

Closed
Dhyey opened this issue Oct 21, 2022 · 46 comments
Closed

Bug: Error: Docker is not reachable (even though it is!) #4329

Dhyey opened this issue Oct 21, 2022 · 46 comments

Comments

@Dhyey
Copy link

Dhyey commented Oct 21, 2022

Description:

Hi, I'm new to AWS SAM and I'm facing issue trying to run sam local start-api.
I've docker perfectly installed and running. I can also run docker run -d -p 80:80 docker/getting-started
I've followed each and every line of the documentation and am still getting this issue.

I would really appreciate if you can help and let me know if it's a bug or there is something I'm doing wrong.

Thanks!

Observed result:

sudo sam local start-api --debug
2022-10-21 12:58:01,423 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-10-21 12:58:01,423 | Using config file: samconfig.toml, config environment: default
2022-10-21 12:58:01,423 | Expand command line arguments to:
2022-10-21 12:58:01,423 | --template_file=/Users/dhyeyshah/Documents/vStory/links-vstory-co-backend/.aws-sam/build/template.yaml --host=127.0.0.1 --port=3000 --static_dir=public --layer_cache_basedir=/Users/dhyeyshah/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1 
2022-10-21 12:58:01,561 | local start-api command is called
2022-10-21 12:58:01,564 | No Parameters detected in the template
2022-10-21 12:58:01,572 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is HelloWorldFunction
2022-10-21 12:58:01,572 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-10-21 12:58:01,573 | 0 stacks found in the template
2022-10-21 12:58:01,573 | No Parameters detected in the template
2022-10-21 12:58:01,578 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is HelloWorldFunction
2022-10-21 12:58:01,578 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-10-21 12:58:01,578 | 2 resources found in the stack 
2022-10-21 12:58:01,578 | Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction'
2022-10-21 12:58:01,578 | --base-dir is not presented, adjusting uri HelloWorldFunction relative to /Users/dhyeyshah/Documents/vStory/links-vstory-co-backend/.aws-sam/build/template.yaml
2022-10-21 12:58:01,580 | Docker is not reachable
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/transport/unixconn.py", line 43, in connect
    sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/transport/unixconn.py", line 43, in connect
    sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/samcli/local/docker/utils.py", line 91, in is_docker_reachable
    docker_client.ping()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/client.py", line 187, in ping
    return self.api.ping(*args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/api/daemon.py", line 166, in ping
    return self._result(self._get(self._url('/_ping'))) == 'OK'
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/api/client.py", line 230, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
2022-10-21 12:58:01,620 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '62545fa7-9156-4ff1-91da-769acb294fdd', 'installationId': 'b741dcb0-1046-4c7e-a4d6-307c96f765df', 'sessionId': '396f5fcf-13d9-418b-b13f-914d27cb3fe0', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.15', 'samcliVersion': '1.60.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local start-api', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '72decab683f6a077f3e3fc1129e7a9faade6cf0cb8fed680bcdafd9f0629b77b', 'initialCommit': None}, 'duration': 197, 'exitReason': 'DockerIsNotReachableException', 'exitCode': 1}}]}
2022-10-21 12:58:02,734 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

Device: Macbook air M1 model
ProductName: macOS
ProductVersion: 12.6
BuildVersion: 21G115

SAM CLI, version 1.60.0

@Dhyey Dhyey added stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. type/bug labels Oct 21, 2022
@Dhyey Dhyey changed the title Bug: Docker is not reachable (even though it is!) Bug: Error: Docker is not reachable (even though it is!) Oct 21, 2022
@camille500
Copy link

Same problem here

Device: Macbook Pro (Intel)
OS: MacOS Montery 12.5
SAM CLI version: 1.60.0
Docker version: 20.10.20

@Tan--Tan
Copy link

Tan--Tan commented Oct 21, 2022

Same problem

Device: Macbook Pro (Apple M1 Pro)
OS: MacOS Monterey 12.6
SAM CLI version: 1.60.0
AWS version: aws-cli/2.8.4 Python/3.9.11 Darwin/21.6.0 exe/x86_64 prompt/off
Docker version: 20.10.20

There is a docker client object at "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/samcli/local/docker/utils.py", but docker_client.ping() is unreachable

@ddhanak
Copy link

ddhanak commented Oct 21, 2022

Same problem here.

Device: Macbook Pro (m1)
OS: MacOS Montery 12.12.1
SAM CLI version: 1.60.0
Docker version 20.10.20, build 9fdeb9c

@mndeveci
Copy link
Contributor

Thanks for reporting this issue. Can you confirm if same behavior happens with sam build --use-container or with sam local invoke?

@mndeveci mndeveci added stage/needs-investigation Requires a deeper investigation and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Oct 21, 2022
@Tan--Tan
Copy link

Thanks for reporting this issue. Can you confirm if same behavior happens with sam build --use-container or with sam local invoke?

both haven't worked for me

@ddhanak
Copy link

ddhanak commented Oct 21, 2022

@mndeveci when I run sam local invoke I get the following output:

❯ sam local invoke        
Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?

and when running docker ps:

❯ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

or when running the getting-started image:

❯ docker run -d -p 80:80 docker/getting-started

1a62222e46992ad6562db635cbee75602dd938656dedd0080a69b0e876b7eab7

@ddhanak
Copy link

ddhanak commented Oct 21, 2022

Same problem here.

Getting an error.

SAM CLI, version 1.60.0

Macbook M1

Running AWS SAM projects locally requires Docker. Have you got it installed and running?

No. I tried a lot of stuff but nothing seems to do it for me.

@mndeveci
Copy link
Contributor

mndeveci commented Oct 21, 2022

We've tried to reproduce issue on both x86 (Intel) and arm (M1) machines.

Bot of them worked with earlier docker version, (M1: 20.10.14, Intel: 20.10.17). Upgrading to latest version (20.10.20) broke the M1 instance, but it was still working with Intel. We will be working on resolution, for a workaround, I would recommend downgrading docker version for now.

Edit: Apologies for earlier version of this comment, but it looks like both M1 and Intel machines are working fine. In previous attempt, docker daemon was not running during the test with M1 machine. After running docker daemon, it worked fine with it as well.

Can you provide how did you install AWS SAM CLI? Did you use homebrew (brew install) or pip install?

@ddhanak
Copy link

ddhanak commented Oct 22, 2022

I get the same error when I use pip install:

❯ which sam
/Users/ddhanak/.pyenv/shims/sam

❯ sam --version
SAM CLI, version 1.60.0

or if I use brew install:

❯ which sam 
/opt/homebrew/bin/sam

❯ sam --version
SAM CLI, version 1.60.0

output:

2022-10-21 22:10:03,783 | Docker is not reachable
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/opt/homebrew/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/opt/homebrew/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/transport/unixconn.py", line 43, in connect
    sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

and the output of docker ps:

❯ docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED       STATUS       PORTS                NAMES
1a62222e4699   docker/getting-started   "/docker-entrypoint.…"   4 hours ago   Up 4 hours   0.0.0.0:80->80/tcp   stoic_joliot

@ddhanak
Copy link

ddhanak commented Oct 22, 2022

We've tried to reproduce issue on both x86 (Intel) and arm (M1) machines.

Bot of them worked with earlier docker version, (M1: 20.10.14, Intel: 20.10.17). Upgrading to latest version (20.10.20) broke the M1 instance, but it was still working with Intel. We will be working on resolution, for a workaround, I would recommend downgrading docker version for now.

Edit: Apologies for earlier version of this comment, but it looks like both M1 and Intel machines are working fine. In previous attempt, docker daemon was not running during the test with M1 machine. After running docker daemon, it worked fine with it as well.

Can you provide how did you install AWS SAM CLI? Did you use homebrew (brew install) or pip install?

I could make it work by downgrading to Docker version 20.10.14, build a224086.

@Dhyey
Copy link
Author

Dhyey commented Oct 22, 2022

Thanks for reporting this issue. Can you confirm if same behavior happens with sam build --use-container or with sam local invoke?

@mndeveci yes the issue also happens with sam build --use-container and sam local invoke

@Dhyey
Copy link
Author

Dhyey commented Oct 22, 2022

We've tried to reproduce issue on both x86 (Intel) and arm (M1) machines.

Bot of them worked with earlier docker version, (M1: 20.10.14, Intel: 20.10.17). Upgrading to latest version (20.10.20) broke the M1 instance, but it was still working with Intel. We will be working on resolution, for a workaround, I would recommend downgrading docker version for now.

Edit: Apologies for earlier version of this comment, but it looks like both M1 and Intel machines are working fine. In previous attempt, docker daemon was not running during the test with M1 machine. After running docker daemon, it worked fine with it as well.

Can you provide how did you install AWS SAM CLI? Did you use homebrew (brew install) or pip install?

@mndeveci
installed AWS SAM cli through brew install

Like @ddhanak, I could also make everything work when I downgraded to https://docs.docker.com/desktop/release-notes/#docker-desktop-470 which uses Docker version 20.10.14, build a224086.

I think you're right that upgrading to latest version of docker (20.10.20) breaks on the M1 instance. (which I run it through https://docs.docker.com/desktop/release-notes/#docker-desktop-4130)

@andybeli
Copy link

andybeli commented Oct 24, 2022

same issue here.

MacOS Monterey: 12.6
Chipset: Apple M1 Pro
Docker version: 20.10.20
SAM CLI version: 1.60.0 (installed through brew)

docker ps
docker run hello-world

running correctly

sam local invoke --debug

2022-10-24 13:29:35,617 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2022-10-24 13:29:35,617 | Using config file: samconfig.toml, config environment: default
2022-10-24 13:29:35,617 | Expand command line arguments to:
2022-10-24 13:29:35,617 | --template_file=/Users/andrebelilos/repos/cyber-sam-test/sam-first-lambda/template.yaml --no_event --layer_cache_basedir=/Users/andrebelilos/.aws-sam/layers-pkg --container_host=localhost --container_host_interface=127.0.0.1
2022-10-24 13:29:35,617 | local invoke command is called
2022-10-24 13:29:35,622 | No Parameters detected in the template
2022-10-24 13:29:35,632 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2022-10-24 13:29:35,632 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-10-24 13:29:35,632 | 0 stacks found in the template
2022-10-24 13:29:35,632 | No Parameters detected in the template
2022-10-24 13:29:35,640 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2022-10-24 13:29:35,640 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2022-10-24 13:29:35,640 | 2 resources found in the stack
2022-10-24 13:29:35,640 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello-world/'
2022-10-24 13:29:35,640 | --base-dir is not presented, adjusting uri hello-world/ relative to /Users/andrebelilos/repos/cyber-sam-test/sam-first-lambda/template.yaml
2022-10-24 13:29:35,643 | Docker is not reachable
Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/transport/unixconn.py", line 43, in connect
    sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/usr/local/Cellar/python@3.8/3.8.15/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/transport/unixconn.py", line 43, in connect
    sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/samcli/local/docker/utils.py", line 91, in is_docker_reachable
    docker_client.ping()
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/client.py", line 187, in ping
    return self.api.ping(*args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/api/daemon.py", line 166, in ping
    return self._result(self._get(self._url('/_ping'))) == 'OK'
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/docker/api/client.py", line 230, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/Cellar/aws-sam-cli/1.60.0/libexec/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
2022-10-24 13:29:35,737 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '0d2b4bf7-21e4-4b6e-9d0c-1440ad23666a', 'installationId': '905bda77-7055-4325-9e78-884e25d4b9f4', 'sessionId': '1d1a84a7-06aa-442c-8c7a-ba3a3aa9066b', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.15', 'samcliVersion': '1.60.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local invoke', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '52a99a5cabfde4de3b5c472e441288d97216d7bb0cb1b021bc23984c29f233e4', 'initialCommit': None}, 'duration': 118, 'exitReason': 'DockerIsNotReachableException', 'exitCode': 1}}]}
2022-10-24 13:29:36,550 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?

@Ariflo
Copy link

Ariflo commented Oct 24, 2022

same issue here.

MacOS Monterey: 12.6
Chipset: Apple M1 Max
Docker version: 20.10.20
SAM CLI version: 1.60.0 (installed through brew)

@jerang
Copy link

jerang commented Oct 24, 2022

Yap, this is definitely an issue - running into the same problem with Docker version 20.10.20 on a M1 Macbook Pro

@ddhanak
Copy link

ddhanak commented Oct 24, 2022

Installing Docker version 20.10.14, build a224086 and upgrading manually fixes my issues but it's still quite weird that we cannot directly install the latest docker version.

@mndeveci
Copy link
Contributor

mndeveci commented Oct 24, 2022

We were able to find the root cause of the issue. I think Docker has changed its behavior with its latest release in terms of setting up the default context for its client.

If you run docker info please check what is the Context value for client configuration. For instance, this one is using desktop-linux which is breaking our use case;

$ docker info
Client:
 Context:    desktop-linux
...

And if you run docker context ls it will show you the context information;

$ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                  KUBERNETES ENDPOINT   ORCHESTRATOR
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                                            swarm
desktop-linux *     moby                                                          unix:///Users/ec2-user/.docker/run/docker.sock

Unfortunately, docker library can't find out which context is been used without connecting to the docker daemon. So in order to fix the issue you need to provide DOCKER_HOST environment variable. So running command with following way will resolve the issue for now (please replace actual host endpoint with what you see from the docker context ls command);

$ DOCKER_HOST=unix:///Users/ec2-user/.docker/run/docker.sock sam build -u

After running this way, SAM CLI commands will be succeeding. Same issue is reported in docker-py repository where we are discussing with them to resolve this issue. (See: docker/docker-py#3059)

@DaDanny
Copy link

DaDanny commented Oct 25, 2022

I had the same issues using an Apple M1 Pro chipset and I was able to get it working by downgrading my version of Docker Desktop to v4.7.0, which I did via this link . I just downloaded that version, ensured Docker Desktop wasn't running on my Macbook and replacing the app in my applications and then restarting Docker Desktop.

@mndeveci
Copy link
Contributor

An update from docker; docker/for-mac#6529 (comment)

They will rollback this change and plan to release it later.

@willianfalbo
Copy link

willianfalbo commented Feb 20, 2023

Even though I updated the Docker Desktop to the latest version, I still face the same error!

Basically, I got a brand new installation (everything from scratch), but I only managed to solve it by running:
sudo ln -sf "$HOME/.docker/run/docker.sock" /var/run/docker.sock as recommended in this answer docker/docker-py#3059 (comment)

@iagardi
Copy link

iagardi commented Mar 1, 2023

I am facing this issue on a daily basis. Have to run sudo ln -sf "$HOME/.docker/run/docker.sock" /var/run/docker.sock daily, or I get 'Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?'

SAM CLI version 1.75.0, Docker desktop engine 20.10.22, Apple M1 Pro

@Aliaksandr-A
Copy link

Docker version 20.10.23, build 7155243
SAM CLI, version 1.76.0

Same issue.

@Jeganprakash
Copy link

same issue.

SAM CLI, version 1.78.0
Docker version 20.10.19
Os: Linux Ubuntu

@yovko-mytaverse
Copy link

yovko-mytaverse commented Mar 30, 2023

Same issue here:

SAM CLI, version 1.78.0
Docker version 20.10.23, build 7155243
OS: macOS 13.3

Downgrading to 20.10.14 is working. But this version is quite outdated.

@snapstreamjoe
Copy link

Same issue here:

SAM CLI, version 1.78.0
Docker version 4.17.0
OS: macOS 13.1

Downgrading to 4.7.0 is working. But this version is quite outdated.

@mengelseatz
Copy link

Same problem
SAM CLI, version 1.78.0
Docker version 4.17.0
OS: macOS 13.1

@sumaiyah
Copy link

Same problem
SAM CLI, version 1.78.0
Docker version 20.10.23
OS: macOS 13.2.1

@nicohiq
Copy link

nicohiq commented Apr 17, 2023

Same problem
SAM CLI, version 1.79.0
Docker version 20.10.24
OS: macOS 13.3.1

@nahue
Copy link

nahue commented Apr 18, 2023

Same problem
SAM CLI, version 1.80.0
Docker version 20.10.24
OS: macOS 13.3.1

work around: sudo ln -sf "$HOME/.docker/run/docker.sock" /var/run/docker.sock

@benmeiri
Copy link

benmeiri commented May 5, 2023

Same issue

SAM CLI, version 1.82.0
Docker version 23.0.5 (docker desktop installation)
OS: macOS 12.6.5 (Intel)

@nahue 's workaround worked for me

@mehulved
Copy link

@nahue's workaround does the trick for now.

% sam --version
SAM CLI, version 1.82.0

% docker --version
Docker version 23.0.5, build bc4487a

% sw_vers
ProductName:		macOS
ProductVersion:		13.3.1
BuildVersion:		22E261

I am on M1 Mac.

@sputnik-adam
Copy link

Same issue. @nahue's workaround did not work for me.

% sam --version
SAM CLI, version 1.84.0
% docker --version
Docker version 23.0.5, build bc4487a
% sw_vers
ProductName:		macOS
ProductVersion:		13.4
BuildVersion:		22F66

@JulieMcManus
Copy link

Same issue. @nahue's work around sorted it for me.

% sam --version
SAM CLI, version 1.84.0
% docker --version
Docker version 23.0.5, build bc4487a
% sw_vers
ProductName:		macOS
ProductVersion:		11.7.3
BuildVersion:		20G1116

@romakov
Copy link

romakov commented Jul 18, 2023

In the docker settings go to Advanced -> Allow the default Docker socket to be used (requires password) and restart docker or Mac. It works for me

@luisdemarchi
Copy link

@romakov success!

Screenshot 2023-07-19 at 13 20 27

@V4G4X
Copy link

V4G4X commented Jul 29, 2023

Still facing this issue. @nahue 's workaround did NOT work for me.

I am not using Docker Desktop but Colima instead. Had this issue even when I was using Docker Desktop. Moved to Colima as a workaround for this.

Docker Version:
Docker version 24.0.5, build ced0996600
Docker Path:
/opt/homebrew/bin/docker

Colima Version:

colima version 0.5.5
git commit: 6251dc2c2c5d8197c356f0e402ad028945f0e830

runtime: docker
arch: x86_64
client: v24.0.5
server: v23.0.6

Colima Path:
/opt/homebrew/bin/colima

SAM Version:
SAM CLI, version 1.94.0
SAM Path:
/usr/local/bin/sam

OS Details:
Darwin Varuns-MacBook-Pro.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:19 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8103 arm64

Logs on running sam local invoke:

❯ sam local start-api --debug
2023-07-29 16:09:53,437 | No config file found in this directory.
2023-07-29 16:09:53,439 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/Users/varungawande/playground/goLambdaDebug/sunflowers/samconfig.toml'
2023-07-29 16:09:53,439 | Config file location: /Users/varungawande/playground/goLambdaDebug/sunflowers/samconfig.toml
2023-07-29 16:09:53,440 | Config file '/Users/varungawande/playground/goLambdaDebug/sunflowers/samconfig.toml' does not exist
2023-07-29 16:09:53,443 | Using SAM Template at /Users/varungawande/playground/goLambdaDebug/sunflowers/.aws-sam/build/template.yaml
2023-07-29 16:09:53,456 | Using config file: samconfig.toml, config environment: default
2023-07-29 16:09:53,457 | Expand command line arguments to:
2023-07-29 16:09:53,457 | --template_file=/Users/varungawande/playground/goLambdaDebug/sunflowers/.aws-sam/build/template.yaml --host=127.0.0.1 --port=3000 --static_dir=public --layer_cache_basedir=/Users/varungawande/.aws-sam/layers-pkg
--container_host=localhost --container_host_interface=127.0.0.1
2023-07-29 16:09:53,515 | local start-api command is called
2023-07-29 16:09:53,518 | No Parameters detected in the template
2023-07-29 16:09:53,530 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is HelloWorldFunction
2023-07-29 16:09:53,531 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2023-07-29 16:09:53,533 | 0 stacks found in the template
2023-07-29 16:09:53,534 | No Parameters detected in the template
2023-07-29 16:09:53,542 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction is HelloWorldFunction
2023-07-29 16:09:53,543 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2023-07-29 16:09:53,543 | 2 resources found in the stack
2023-07-29 16:09:53,544 | Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction'
2023-07-29 16:09:53,544 | --base-dir is not presented, adjusting uri HelloWorldFunction relative to /Users/varungawande/playground/goLambdaDebug/sunflowers/.aws-sam/build/template.yaml
2023-07-29 16:09:53,547 | Docker is not reachable
Traceback (most recent call last):
  File "urllib3/connectionpool.py", line 703, in urlopen
  File "urllib3/connectionpool.py", line 398, in _make_request
  File "urllib3/connection.py", line 244, in request
  File "http/client.py", line 1256, in request
  File "http/client.py", line 1302, in _send_request
  File "http/client.py", line 1251, in endheaders
  File "http/client.py", line 1011, in _send_output
  File "http/client.py", line 951, in send
  File "docker/transport/unixconn.py", line 27, in connect
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "requests/adapters.py", line 486, in send
  File "urllib3/connectionpool.py", line 787, in urlopen
  File "urllib3/util/retry.py", line 550, in increment
  File "urllib3/packages/six.py", line 769, in reraise
  File "urllib3/connectionpool.py", line 703, in urlopen
  File "urllib3/connectionpool.py", line 398, in _make_request
  File "urllib3/connection.py", line 244, in request
  File "http/client.py", line 1256, in request
  File "http/client.py", line 1302, in _send_request
  File "http/client.py", line 1251, in endheaders
  File "http/client.py", line 1011, in _send_output
  File "http/client.py", line 951, in send
  File "docker/transport/unixconn.py", line 27, in connect
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "samcli/local/docker/utils.py", line 90, in is_docker_reachable
  File "docker/client.py", line 203, in ping
  File "docker/api/daemon.py", line 166, in ping
  File "docker/utils/decorators.py", line 46, in inner
  File "docker/api/client.py", line 237, in _get
  File "requests/sessions.py", line 602, in get
  File "requests/sessions.py", line 589, in request
  File "requests/sessions.py", line 703, in send
  File "requests/adapters.py", line 501, in send
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
2023-07-29 16:09:53,551 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-07-29 16:09:53,587 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-07-29 16:09:53,588 | Unable to find Click Context for getting session_id.
2023-07-29 16:09:53,588 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'e707c714-1afb-41ac-93f7-c8d2d2b7bd85', 'installationId': '2a43a88c-7a44-4ea7-8f6b-548d63c704d9', 'sessionId': '3c57a858-113a-44b2-98ff-f7afb2e501fc',
'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13', 'samcliVersion': '1.94.0', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id':
'756374beeff242c6a1ea2e944c7c0f47', 'time_stamp': '2023-07-29 10:39:53.439', 'exception_name': None}]}}}]}
2023-07-29 16:09:53,588 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '094cfaa6-a5f3-4e86-ba70-3957ad9c52ac', 'installationId': '2a43a88c-7a44-4ea7-8f6b-548d63c704d9', 'sessionId': '3c57a858-113a-44b2-98ff-f7afb2e501fc',
'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13', 'samcliVersion': '1.94.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam local start-api', 'metricSpecificAttributes':
{'projectType': 'CFN', 'gitOrigin': None, 'projectName': 'a9d90bce792e70da6e7c44cf8859e964b13e8e21dfedf17971e1a6ce77a105de', 'initialCommit': None}, 'duration': 94, 'exitReason': 'DockerIsNotReachableException', 'exitCode': 1}}]}
2023-07-29 16:09:54,323 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?
2023-07-29 16:09:54,326 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

@ghoshpushpendu
Copy link

Docker Desktop 4.21.1 (114176) is currently the newest version available.
And this version still has the issue on mac.

@V4G4X
Copy link

V4G4X commented Aug 3, 2023

@ghoshpushpendu
Check this out.

It worked for me, my issue was with catalina, but in your case if you modify the path to get Docker Desktop's context (probably unix:///Users/{username}/.docker/run/docker.sock) it might work for you.

@tuminzee
Copy link

We were able to find the root cause of the issue. I think Docker has changed its behavior with its latest release in terms of setting up the default context for its client.

If you run docker info please check what is the Context value for client configuration. For instance, this one is using desktop-linux which is breaking our use case;

$ docker info
Client:
 Context:    desktop-linux
...

And if you run docker context ls it will show you the context information;

$ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                  KUBERNETES ENDPOINT   ORCHESTRATOR
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                                            swarm
desktop-linux *     moby                                                          unix:///Users/ec2-user/.docker/run/docker.sock

Unfortunately, docker library can't find out which context is been used without connecting to the docker daemon. So in order to fix the issue you need to provide DOCKER_HOST environment variable. So running command with following way will resolve the issue for now (please replace actual host endpoint with what you see from the docker context ls command);

$ DOCKER_HOST=unix:///Users/ec2-user/.docker/run/docker.sock sam build -u

After running this way, SAM CLI commands will be succeeding. Same issue is reported in docker-py repository where we are discussing with them to resolve this issue. (See: docker/docker-py#3059)

Thanks a lot. This helped

@jhua8970
Copy link

jhua8970 commented Nov 1, 2023

In the docker settings go to Advanced -> Allow the default Docker socket to be used (requires password) and restart docker or Mac. It works for me

This worked for me. My SAM CLI stoped working after a Docker upgrade and I was stumped for hours until I found this solution.

@thatShashankGuy
Copy link

In the docker settings go to Advanced -> Allow the default Docker socket to be used (requires password) and restart docker or Mac. It works for me

Thank you !. This is the fix for for Docker version 24.0.6, build ed223bc on Mac M1

@rafaizidoro
Copy link

In the docker

Thanks! This solution was effective for me as well 🚀

@jorporta
Copy link

In the docker settings go to Advanced -> Allow the default Docker socket to be used (requires password) and restart docker or Mac. It works for me

Thank you !. This is the fix for for Docker version 24.0.6, build ed223bc on Mac M1

Worked for me as well!! No need to restart the mac. Thanks!

@ishandandekar
Copy link

ishandandekar commented Dec 29, 2023

Same issue for me

SAM CLI, version 1.103.0
❯ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                  KUBERNETES ENDPOINT   ORCHESTRATOR
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                                            
desktop-linux *     moby                Docker Desktop                            unix:///home/ishan/.docker/desktop/docker.sock  

Is there anythign I can do, please help, I've been at this for 3 hours

@0cv
Copy link

0cv commented Jan 23, 2024

In the docker settings go to Advanced -> Allow the default Docker socket to be used (requires password) and restart docker or Mac. It works for me

Thank you !. This is the fix for for Docker version 24.0.6, build ed223bc on Mac M1

Worked for me as well!! No need to restart the mac. Thanks!

It happened for me all of a sudden, and I already had that setting on. The fix for me was simply to restart Docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests