Skip to content

Instantly share code, notes, and snippets.

@fortinux
Created January 28, 2023 10:40
Show Gist options
  • Save fortinux/4dff8a7d72dee0e012d739f3872ea3d0 to your computer and use it in GitHub Desktop.
Save fortinux/4dff8a7d72dee0e012d739f3872ea3d0 to your computer and use it in GitHub Desktop.
How to resolve Error: Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock

How to resolve Error

Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

  • My setup: Ubuntu 22.04, Terraform, Docker Desktop

When you try to follow the first tutorial at Terraform and do terraform apply you get the message above. It tooks me a couple of hours to discover that Docker Desktop in Ubuntu 22.04 don't use unix:///var/run/docker.sock as DOCKER ENDPOINT but unix:///home/user/.docker/desktop/docker.sock so the solution that works is this:

  • Check your DOCKER ENDPOINT opening a terminal and typing:

docker context ls

  • Look there and copy your DOCKER ENDPOINT
  • Open your main.tf and change provider line, i.e:
provider "docker" {
  host ="unix:///home/user/.docker/desktop/docker.sock"
}
  • Save and do again:
terraform init
terraform apply

Docs that helps me resolve this issue:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment