5

I'm trying to work my way through the Import Terraform Configuration tutorial on the learn.hashicorp.com site. When I try to run the terraform import command in the tutorial, I get the following error:

$ terraform import docker_container.web $(docker inspect --format="{{.ID}}" hashicorp-learn)
╷
│ Error: Error initializing Docker client: protocol not available
│ 
│   with provider["registry.terraform.io/kreuzwerker/docker"],
│   on /Users/ac8dqzz/myrepos/terraform/learn-terraform-import/main.tf line 14, in provider "docker":
│   14: provider "docker" {
│ 
╵

Googling this error has not yielded anything of relevance to my particular case. My main.tf file looks like this:

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 2.16"
    }
  }
  required_version = ">= 0.14"
}

provider "docker" {
  host    = "npipe:////.//pipe//docker_engine"
}

Can anyone suggest what the problem here is?

Paul
  • 163
  • 1
  • 7

4 Answers4

12

Replace host = "npipe:////.//pipe//docker_engine" with host = "unix:///var/run/docker.sock" its works for me in mac. see the complete solution below:

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 2.7"
    }
  }
  required_version = ">= 0.14"
}

provider "docker" {
  host = "unix:///var/run/docker.sock"
}
0

make sure that the docker is running (use docker ps) before terraform apply.

0

I had to run two commands terraform init and terraform apply as root user and then it worked :)

PavanDevarakonda
  • 625
  • 5
  • 27
nikki_g24
  • 1
  • 2
0

Replace host = "npipe:////.//pipe//docker_engine" with host = "unix:///var/run/docker.sock" it worked for me also on Linux (Rocky9)