AWS Lambda Sam 找不到 docker

AWS Lambda Sam can't find docker

我正在尝试使用 aws-sam-cli 在我的项目根文件夹中使用以下命令测试我的 hello world lambda 函数:

sam local start-api --debug

这在控制台中给出了以下输出:

2018-07-11 16:13:15 local start-api command is called
2018-07-11 16:13:15 2 resources found in the template
2018-07-11 16:13:15 Found Serverless function with name='Hello' and CodeUri='.'
2018-07-11 16:13:15 Trying paths: ['/home/jamiro/.docker/config.json', '/home/jamiro/.dockercfg']
2018-07-11 16:13:15 No config file found
2018-07-11 16:13:15 Trying paths: ['/home/jamiro/.docker/config.json', '/home/jamiro/.dockercfg']
2018-07-11 16:13:15 No config file found
Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

据我所知,我确实安装了 docker,因为执行 docker --version 会产生以下输出:

Docker version 18.03.1-ce, build 9ee9f40

有谁知道为什么 sam 找不到 docker?

按照以下步骤操作:

  1. 删除 ~/.docker 目录
  2. 创建 "docker" 群组
  3. 将我的用户添加到 "docker" 组
  4. 注销并重新登录
  5. 重新启动 "docker" 守护程序。

更多信息在 Docker postinstall instructions

我安装了 docker 的旧版本。尽管 docker 工作正常,但 sam 无法正确检测到它。

sam local start-api --debug

docker.errors.APIError: 400 Client Error: Bad Request ("client is newer than server (client API version: 1.35, server API version: 1.24)") Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

我删除了旧版本和 re-installed docker.io 包(在 Ubuntu 下)。然后我启动了 docker 守护进程,问题就解决了。

在 windows 中安装 Docker 时,确保安装 linux 内核更新,安装后 window 提示:

https://docs.microsoft.com/es-es/windows/wsl/install-win10#step-4---download-the-linux-kernel-update-package

安装更新后docker应该重新启动(否则手动重新启动,或重新启动计算机)并且 SAM 应该能够找到它。