Reputation: 313
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?
Upvotes: 7
Views: 5235
Reputation: 1
Replace host = "npipe:////.//pipe//docker_engine" with host = "unix:///var/run/docker.sock" it worked for me also on Linux (Rocky9)
Upvotes: 0
Reputation: 1
I had to run two commands terraform init
and terraform apply
as root user and then it worked :)
Upvotes: 0
Reputation: 31
make sure that the docker is running (use docker ps
) before terraform apply
.
Upvotes: 0
Reputation: 151
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"
}
Upvotes: 15