Kreuzworker/docker: "protocol not available" error when initializing Docker client

Hello -

I installed terraform on WSL Ubuntu 22.04.3 LTS and it seems to be installed fine.

I installed Docker Desktop for Windows and the WSL Ubuntu doesn’t seem to be communicating with Docker. I get the following error:

Error: Error initializing Docker client: protocol not available

│ with provider[“Terraform Registry”],
│ on main.tf line 10, in provider “docker”:
│ 10: provider “docker” {

What does the Terraform configuration look like? Example here:

https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs

Specifically, what is your host address set to? I don’t have an environment available at the moment to try and set this up, but seems similar to local - WSL2 use "localhost" to access Windows service - Stack Overflow

Also, you can run Terraform on Windows as well.

terraform {
required_providers {
docker = {
source = “kreuzwerker/docker”
version = “~> 3.0.1”
}
}
}

provider “docker” {
host = “tcp://localhost:2375”
}

resource “docker_image” “nginx” {
name = “nginx”
keep_locally = false
}

resource “docker_container” “nginx” {
image = docker_image.nginx.image_id
name = “tutorial”

ports {
internal = 80
external = 8000
}
}

I keep getting this error:

Error: Error pinging Docker server: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

│ with provider[“Terraform Registry”],
│ on main.tf line 10, in provider “docker”:
│ 10: provider “docker” {

Unless you have set up some port forwarding in WSL to send traffic targeted at port 2375 back to the address of the Windows host, I would expect Terraform is looking at your WSL instance, not at Windows for Docker. Check out the Stackoverflow link above as it has the steps to get the hostname.

Or, unless running Terraform in WSL and Docker in Windows is a hard requirement, download Terraform for Windows and run it there.