AWS Lambda Sam can't find docker
Asked Answered
G

7

16

I'm trying to test my hello world lambda function with aws-sam-cli using the following command in my project root folder:

sam local start-api --debug

This gives me the following output in the console:

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?

To my understanding, I do have docker installed, as performing docker --version results in the following output:

Docker version 18.03.1-ce, build 9ee9f40

Does anyone one have an idea why sam can't find docker?

Gomer answered 11/7, 2018 at 14:18 Comment(6)
Run which docker. Where does it say Docker is installed?Trichology
it returns /usr/bin/dockerGomer
may this quiestion helps you?Exploratory
@Exploratory That seems to have fixed it, thanks! I'm not sure what the standard procedure is when a comment answers the question. Do you post it as a seperate answer so that I can accept it?Gomer
Just added an answerExploratory
Possible duplicate of Running AWS SAM projects locally get errorCentering
E
14

Follow these steps:

  1. Delete the ~/.docker directory
  2. Create the "docker" group
  3. Add my user to the "docker" group
  4. Logout and back in again
  5. Restart the "docker" daemon.

More info in the Docker postinstall instructions

Exploratory answered 11/7, 2018 at 15:22 Comment(1)
Important to log out and back in again for this to work. I read the linked instructions and thought a restart could be avoided but apparently not.Polished
H
2

I had an older version of docker installed. Although docker was working fine, sam could not detect it properly.

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?

I removed the old version and re-installed the docker.io package (under Ubuntu). Then I started the docker daemon and the issue was fixed.

Harmattan answered 14/5, 2019 at 14:53 Comment(0)
F
2

this is mostly related to DOCKER_HOST not being set try running it like this and it will work

 sudo DOCKER_HOST=unix://$HOME/.docker/run/docker.sock  sam build -c  
Fannie answered 2/4 at 8:43 Comment(0)
T
1

When installing Docker in windows make sure to install the linux kernel update that you get from a prompt window after installation:

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

After the update has been installed docker should restart (otherwise restart manually, or restart computer) and SAM should be able to find it ok.

Tephra answered 18/3, 2021 at 22:16 Comment(1)
Also, in Windows, before installing anything, it's useful to check if Docker itself is run. The easiest way to do this is to run Docker Desktop which in turn will run the necessary services. For me the error disappeared after this.Jamin
C
1

If this issue arises on Mac, I was able to solve this problem by implementing file sharing on the parent folder. AWS SAM requires file sharing to function, which presents this same error.

Clearway answered 23/8, 2022 at 17:46 Comment(0)
A
0

I had the same issue on my M1 Mac and I had the docker desktop version 4.18.0. installed. I was able to solve my issue by downgrading docker to version 4.15.0.

Abaft answered 21/4, 2023 at 18:10 Comment(0)
R
0

I had the same issue because I accidentally ran the command

sam local start-api

without sudo. I just had to type it like

sudo sam local start-api

Maybe it will help somebody and prevent them from reinstalling docker.

Raymonraymond answered 9/6, 2023 at 12:17 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Kannry

© 2022 - 2024 — McMap. All rights reserved.