5

Im running AWS SAM and using sam build --use-container then get the following error.

Starting Build inside a container Building function 'SamTutorialFunction Build Failed Error: Docker is unreachable. Docker needs to be running to build inside a container

I run sudo service docker start before and still get the same error.

Ordep81
  • 967
  • 4
  • 13
  • 18

5 Answers5

4

I had the same issue. The problem was that docker was installed to run as the root user. AWS SAM is trying to access as your logged in user. You can set docker to run as non-root user (without sudo) by adding your user to the docker group. See https://docs.docker.com/engine/install/linux-postinstall/

dev.cycle
  • 41
  • 2
  • Specifically, on Ubuntu the following commands did the trick for me: `$ sudo usermod -aG docker $USER` `$ newgrp docker` – Bas Krahmer Oct 05 '22 at 09:47
2

sudo ln -s "$HOME/.docker/run/docker.sock" /var/run/docker.sock

work for me

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 08 '23 at 05:44
  • See also https://github.com/aws/aws-sam-cli/issues/5646#issuecomment-1658320645 – Justin M. Keyes Aug 21 '23 at 09:22
1

If you are running Ubuntu on WSL2, You need to enable integration between Docker and WSL2 in order to run

sam build --use-container

Steps:

  1. Download Docker Desktop https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe
  2. Go to settings => resources => WSL integration.
  3. Check the enable integration with additional distros.
Bobberman
  • 99
  • 1
0

In my case the issue was that I did not have the DOCKER_HOST env variable set, I am using Docker Desktop for Linux so first i ran

docker context ls

to get the DOCKER ENDPOINT and set the DOCKER_HOST env variable to the endpoint value

helvete
  • 2,455
  • 13
  • 33
  • 37
0

If you are using another tool like Rancher Desktop, you must start it with root access in order to be able to work with /var/run/docker.sock.

Search in settings how to enable it in your tool, for Rancher Desktop you can go to Main APP icon > Open preferences dialog and enable Administrative Access option.

Eduardo Cuomo
  • 17,828
  • 6
  • 117
  • 94