Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error initializing Docker client: protocol not available running terraform import command

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?

like image 295
Paul Avatar asked Jul 18 '26 05:07

Paul


1 Answers

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"
}
like image 52
Rajeev Sharma Avatar answered Jul 19 '26 21:07

Rajeev Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!