Cannot connect to docker daemon

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[""]

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.


Im having the same issue. If anyone can point us into a direction that fixes this that would be great!

i think terraform cloud agent seems not have docker engine installed by default there so it won’t work

Hi @jaismith,

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.

1 Like

@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.

did you ever find a solution/workaround to use terraform cloud together with the docker provider?

I don’t believe that is supported by Terraform Cloud

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 share the solution for my case (I’m on Ubuntu 22.04, Docker Desktop, Terraform).

  • Check your DOCKER ENDPOINT opening a terminal and typing:

docker context ls

  • Look there and copy your DOCKER ENDPOINT
  • Open your and change provider line, i.e:
provider "docker" {
  host ="unix:///home/user/.docker/desktop/docker.sock"
  • Save and do again:
terraform init
terraform apply

Docs that helps me resolve this issue:

1 Like

You need to change the execution mode in the Cloud settings to local as described here: