docker up and running on my Mac but "sam local invoke" command results in Error: Running AWS SAM projects locally requires Docker
Asked Answered
K

2

6

I have Docker up and running on my Mac. But "sam local invoke" command results in Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?

Anyone knows what could be the reason?

Kike answered 23/10, 2022 at 18:13 Comment(2)
docker command line is working for you?Animatism
@Animatism , yes , I am able to run "docker ps" and "docker run hello-world" commands successfully.Kike
N
12

I installed Docker using the GUI with all default presets and I was having the same issue. I fixed this same issue using Docker's dashboard.

Settings -> Advanced -> Allow the default Docker socket to be used (requires password)

By enabling it, it "Creates /var/run/docker.sock which some third-party clients may use to communicate with Docker Desktop"

Nutrilite answered 9/10, 2023 at 11:6 Comment(2)
using the docker host variable didn't work for me. I spent hours hunting through the internet and this was what helped. Mac pro 16 2019 (intel) SonomaSweetheart
This fixed it for me as well MBP 16" 2019 latest osx.Platina
P
10

There was a change Docker Desktop's default context settings.

On Mac, it may default to desktop-linux if symlink to /var/run/docker.sock was not created. This seems to cause problem with SAM CLI (and probably, a lot of other apps) that expects to communicate with Docker using this socket.

The easiest way to fix this is to set DOCKER_HOST environment variable to point to the socket file associated with desktop-linux.

Run export DOCKER_HOST="unix://Users/<username>/.docker/run/docker.sock"

(add this to your .zshrc or .bashrc file so that you don't have to define the variable every time you start a shell)

and then try running sam command.

Psychokinesis answered 23/1, 2023 at 23:58 Comment(2)
It works! After running this command and then sam local invoke, it began building the image.Dustpan
You Sir are a hero. This worked as expected on my macbook.Negligence

© 2022 - 2024 — McMap. All rights reserved.