I started to learning terraform, I have installed terraform and docker desktop on my macbook. I am following the quick start tutorial and got below error.
ERROR
╷
│ Error: Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
│
│   with provider["registry.terraform.io/kreuzwerker/docker"],
│   on main.tf line 10, in provider "docker":
│   10: provider "docker" {}
│
Docker status
    ❯ docker --version
    Docker version 20.10.20, build 9fdeb9c
    ❯ docker ps
    CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                NAMES
    f6633f3b801e   docker/getting-started   "/docker-entrypoint.…"   2 minutes ago   Up 2 minutes   0.0.0.0:80->80/tcp   flamboyant_volhard
main.tf
    terraform {
      required_providers {
        docker = {
          source  = "kreuzwerker/docker"
          version = "~> 2.13.0"
        }
      }
    }
    
    provider "docker" {}
    
    resource "docker_image" "nginx" {
      name         = "nginx:latest"
      keep_locally = false
    }
    
    resource "docker_container" "nginx" {
      image = docker_image.nginx.latest
      name  = "tutorial"
      ports {
        internal = 80
        external = 8000
      }
    }
Issue has been resolved, solution available in this link
 
                        
Based on the provider documentation [1] (as the error describes as well), you need to switch to the following:
The example from the tutorial is using a very old version of Docker provider. When you make these changes, make sure to run
terraform init -upgradeprior to runningterraform planorterraform apply.[1] https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container#example-usage