ubuntu 尽管Docker正在运行,AWS SAM仍出错

vptzau2j  于 2023-05-16  发布在  Docker
关注(0)|答案(1)|浏览(104)

我正在尝试在Ubuntu 22.04 jammy上本地运行AWS Lambda项目。但是,当我使用AWS SAM Local执行项目时,会显示此错误。错误:在本地运行AWS SAM项目需要Docker。你安装好了吗?“
我安装并运行了SAM CLI版本1.79.0和Docker Desktop
我试着跟踪these steps,但两者都是:“sudo sam local start-api”和“sam local invoke HelloWorldFunction”给出了这个错误

yyhrrdl8

yyhrrdl81#

我在Ubuntu 22.04和Budgie Desktop 10.6.1- 1ubuntu 3中遇到了同样的问题。SAM版本1.82,并尝试使用Docker桌面版本4.15和4.19。我也得到了sam build命令中提到的相同错误。
我确实注意到,如果我完全安装docker并停在那里,SAM CLI似乎可以工作。(注意:我确实将.docker/config.json“credsStore”更改为“credStore”,但我不知道这是否是它工作的原因。)只有当我安装docker desktop时,我才再次收到此错误。
我试过在default和desktop-linux之间切换docker context,但没有成功。还要注意,我确实创建了docker组,并且我的用户是其中的一部分。是的,Docker确实在运行。
虽然这不一定是答案,但我希望更多的信息是有帮助的!
我在下面附上了sam build的调试日志:

2023-05-11 10:54:32,809 | Config file location: /home/<user>/<company>/cloud.<company>-lambda/samconfig.toml
2023-05-11 10:54:32,809 | Config file '/home/<user>/<company>/cloud.<company>-lambda/samconfig.toml' does not exist
2023-05-11 10:54:32,811 | Using SAM Template at /home/<user>/<company>/cloud.<company>-lambda/template.yaml
2023-05-11 10:54:32,825 | Using config file: samconfig.toml, config environment: default
2023-05-11 10:54:32,825 | Expand command line arguments to:
2023-05-11 10:54:32,825 | --template_file=/home/<user>/<company>/cloud.<company>-lambda/template.yaml --mount_with=READ --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache 
2023-05-11 10:54:32,899 | 'build' command is called
2023-05-11 10:54:32,900 | No Parameters detected in the template
2023-05-11 10:54:32,914 | There is no customer defined id or cdk path defined for resource MakeFolderTree, so we will use the resource logical id as the resource id
2023-05-11 10:54:32,914 | 0 stacks found in the template
2023-05-11 10:54:32,914 | No Parameters detected in the template
2023-05-11 10:54:32,922 | There is no customer defined id or cdk path defined for resource MakeFolderTree, so we will use the resource logical id as the resource id
2023-05-11 10:54:32,922 | 1 resources found in the stack 
2023-05-11 10:54:32,922 | Found Serverless function with name='MakeFolderTree' and ImageUri='None'
2023-05-11 10:54:32,922 | --base-dir is not presented, adjusting uri ./MakeFolderTree relative to /home/<user>/<company>/cloud.<company>-lambda/template.yaml
2023-05-11 10:54:32,922 | --base-dir is not presented, adjusting uri . relative to /home/<user>/<company>/cloud.<company>-lambda/template.yaml
2023-05-11 10:54:32,924 | 1 resources found in the stack 
2023-05-11 10:54:32,924 | Found Serverless function with name='MakeFolderTree' and ImageUri='None'
2023-05-11 10:54:32,925 | Error occurred while trying to track an event: Event 'BuildFunctionRuntime' does not accept value 'None'.
2023-05-11 10:54:32,925 | Instantiating build definitions
2023-05-11 10:54:32,927 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(None, /home/<user>/<company>/cloud.<company>-lambda, Image, , 5132ac96-80da-4674-87cc-f9f25d756df2, {'Dockerfile': 'Dockerfile', 'DockerContext': '/home/<user>/<company>/cloud.<company>-lambda/MakeFolderTree', 'DockerTag': 'nodejs10.x'}, {}, x86_64, []), Function: Function(function_id='MakeFolderTree', name='MakeFolderTree', functionname='MakeFolderTree', runtime=None, memory=1408, timeout=60, handler=None, imageuri=None, packagetype='Image', imageconfig=None, codeuri='/home/<user>/<company>/cloud.<company>-lambda', environment=None, rolearn='arn:aws:iam::974208700040:role/lambda_basic_execution', layers=[], events=None, metadata={'Dockerfile': 'Dockerfile', 'DockerContext': '/home/<user>/<company>/cloud.<company>-lambda/MakeFolderTree', 'DockerTag': 'nodejs10.x', 'SamResourceId': 'MakeFolderTree'}, inlinecode=None, codesign_config_arn=None, architectures=['x86_64'], function_url_config=None, stack_path='', runtime_management_config=None))
2023-05-11 10:54:32,928 | Building codeuri: /home/<user>/<company>/cloud.<company>-lambda runtime: None metadata: {'Dockerfile': 'Dockerfile', 'DockerContext': '/home/<user>/<company>/cloud.<company>-lambda/MakeFolderTree', 'DockerTag': 'nodejs10.x'} architecture: x86_64 functions: MakeFolderTree
2023-05-11 10:54:32,928 | Building to following folder /home/<user>/<company>/cloud.<company>-lambda/.aws-sam/build/MakeFolderTree
2023-05-11 10:54:32,928 | Building image for MakeFolderTree function
2023-05-11 10:54:32,930 | Docker is not reachable
Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 976, in send
    self.connect()
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/docker/transport/unixconn.py", line 43, in connect
    sock.connect(self.unix_socket)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/http/client.py", line 976, in send
    self.connect()
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/docker/transport/unixconn.py", line 43, in connect
    sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', PermissionError(13, 'Permission denied'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/samcli/local/docker/utils.py", line 90, in is_docker_reachable
    docker_client.ping()
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/docker/client.py", line 187, in ping
    return self.api.ping(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/docker/api/daemon.py", line 166, in ping
    return self._result(self._get(self._url('/_ping'))) == 'OK'
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/docker/api/client.py", line 230, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/aws-sam-cli/1.82.0/libexec/lib/python3.11/site-packages/requests/adapters.py", line 547, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', PermissionError(13, 'Permission denied'))

Build Failed
2023-05-11 10:54:32,932 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-05-11 10:54:32,936 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '1b843b94-1527-43a7-9c2b-a2b7914b782f', 'installationId': 'ed34737c-c8fa-402f-adba-982cead8236e', 'sessionId': 'd986c649-0972-4eb0-a11c-c69a1fd21a43', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.11.3', 'samcliVersion': '1.82.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '10f232b10c21874a47176fa6705e6eb42ee9fa15fa237cb3c32ebff832e198e1', 'initialCommit': None}, 'duration': 107, 'exitReason': 'DockerConnectionError', 'exitCode': 1}}]}
2023-05-11 10:54:33,200 | Telemetry response: 200
Error: Building image for MakeFolderTree requires Docker. is Docker running?

相关问题