Having some trouble getting the docker provider (kreuzwerker/docker) running on terraform cloud. I’ve tried several different ‘host’ addresses for the provider when initializing (I’m using CDKTF), but always get the same error (obviously with different paths):
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"]
Is there some special setup I need to do to get this working with the terraform cloud remote backend? I do have docker for MacOS installed locally, but I imagine this is looking for a docker daemon to be running on the cloud backend… I have run terraform init successfully, and terraform providers does return a kreuzwerker/docker version installed.
The default remote operations mechanism where Terraform is running in an execution environment managed by Terraform Cloud itself is not appropriate for working with APIs that are accessible only on your local network or local computer. The hosted execution environment is intended for the case of working with cloud services whose APIs are available on the public internet.
For services running directly on your local computer I would suggest disabling remote operations altogether and just running Terraform locally so it can reach your localhost server.
For shared services running on a local network, you can potentially run an agent in that same network to allow Terraform to run there and access services that the hosted agents would not be able to reach.
@apparentlymart we don’t want to work with APIs on our machine, we’re trying to interact with docker daemon at all, to be able to use the docker provider altogether.
If you specify (in the host provider configuration argument) the address of a Docker daemon that the Terraform Cloud execution environment can reach then I don’t see any reason why it shouldn’t work.
The typical challenge is just that most of the time folks don’t configure a Docker daemon to listen on the public internet, and the hosted Terraform Cloud execution environment can only connect to services that are reachable over the internet. That’s why I was discussing different approaches that will lead to Terraform Core running in a different location that hopefully can reach a Docker daemon that otherwise isn’t available on the internet.
I had the same problem but finally managed to fix. Before running terraform apply, check where the docker daemon is running using docker context ls. The default option may not work, thus the error most people get. Pick the one with *. Then go to the file <main.tf>, edit it to reflect the host as below: