Ordep81
Ordep81

Reputation: 1107

AWS SAM: Build Failed Error: Docker is unreachable. Docker needs to be running to build inside a container

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.

Upvotes: 13

Views: 12230

Answers (9)

Alessandro Salvetti
Alessandro Salvetti

Reputation: 104

I had this problem too, and solve it. On Ubuntu, Docker Desktop runs the docker engine into a Virtual Machine. Sometimes this gives problem for other software to connect with it. The solution I found, was to install docker-engine next to Docker Desktop... yes they can coexist see here.

After you installed docker-engine, close Docker Desktop, and try the hello word package to see if the docker-engine you installed is running.

sudo docker run hello-world

Try to run it with and without "sudo". If you have problem without "sudo" check the user permission as suggested here

Upvotes: 3

Daniel Afonso
Daniel Afonso

Reputation: 30

In case you are using colima try the bellow command in the terminal.

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

This will expose the colima socket file through the default location docker exposes the socket file which is /var/run/docker.sock

Upvotes: 0

DarkTrick
DarkTrick

Reputation: 3487

This helped me:

export DOCKER_HOST=$(docker context inspect | jq -r '.[0].Endpoints.docker.Host')

Source: https://github.com/aws/aws-sam-cli/issues/5646#issuecomment-1812615966

Problem seems to be that DOCKER_HOST is not set in the first place.

Upvotes: 0

Muhammad Faizan Shah
Muhammad Faizan Shah

Reputation: 393

running it like this worked for me

sudo DOCKER_HOST=unix://$HOME/.docker/run/docker.sock  sam build -c  

Upvotes: 0

William Portillo
William Portillo

Reputation: 151

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

work for me

Upvotes: 15

Eduardo Cuomo
Eduardo Cuomo

Reputation: 18937

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.

Upvotes: 1

adrian najera
adrian najera

Reputation: 55

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

Upvotes: 2

Bobberman
Bobberman

Reputation: 99

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.

Upvotes: 1

dev.cycle
dev.cycle

Reputation: 41

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/

Upvotes: 4

Related Questions