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