26

I am trying to run an AWS Lambda project locally on Ubuntu. When I run the project with AWS SAM Local it shows me this error: Error: Running AWS SAM projects locally requires Docker. Have you got it installed?

WhiteHotLoveTiger
  • 2,088
  • 3
  • 30
  • 41
Santosh Silwal
  • 475
  • 1
  • 4
  • 10

7 Answers7

15

Another cause for this is this recent issue within Docker for Mac.

A quick workaround, as specified in the issue itself, is to run SAM with:

$ DOCKER_HOST=unix://$HOME/.docker/run/docker.sock sam local start-api

You don't need to run SAM as root.

schiavuzzi
  • 764
  • 4
  • 9
  • I have Docker Desktop installed on Linux. This worked with a slight modification, since `docker.sock` lives under `~/.docker/desktop`. – Carlos Hanson Jan 26 '23 at 00:20
  • This worked for me 22/3/23 on a Mac with up-to-date docker installed and available on the CL. – JohnAllen Mar 22 '23 at 14:08
14

I had trouble installing it on Fedora.

When I followed the Docker postinstall instructions I managed to get past this issue.

https://docs.docker.com/install/linux/linux-postinstall/

I had to:

  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.

I was then able to run the command:

sam local start-api
Dystopic64
  • 241
  • 2
  • 4
8

If you want to run local sam-cli, you have first install docker from docker official website then run sudo sam local start-api. Note that sudo is necessary for running local developer with needed privileges.

Sagar
  • 4,473
  • 3
  • 32
  • 37
  • 1
    running as root worked for me, do you know why this is necessary? – ekcrisp Oct 04 '18 at 18:25
  • It should have to do with docker having to be invoked with sudo. I think that as of docker version 19 one can run it sudoless, but there are some caveats. All this is just a guess though. – geo909 Apr 22 '20 at 09:50
4

This error mostly arises due to lack of admin privilege to use docker. Just add sudo to your command. This will work. eg: sudo sam local start-api --region eu-west-3

ashique
  • 935
  • 2
  • 8
  • 26
3

I am using colima for docker on mac with intel chip. and faced this error. was able to resolve it by adding DOCKER_HOST in .zshrc file

vi ~/.zshrc

paste export DOCKER_HOST="unix://$HOME/.colima/docker.sock" in the .zshrc file escape :wq

Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73
2

We are working on Mac and were seeing same message when using an older version of Docker (1.12.6). Have since updated to a newer (but not latest) version 17.12.0-ce-mac49 and it is now fine.

0

For those with Macs and using colima for docker, check two things:

  1. ~/.zshrc or ~/.bashrc have DOCKER_HOST pointed to unix://$HOME/.colima/docker.sock", like export DOCKER_HOST="unix://$HOME/.colima/docker.sock"

  2. Make sure colima is actually running. colima start

Dave
  • 21
  • 6