Docker provider tutorial + macOS error

I’m working through the official Terraform + Docker provider tutorial (on a Mac), and seeing this error when running terraform plan (or apply):

Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I’ve followed the rest of the instructions, Docker Desktop is running, docker ps shows:


Without Docker Desktop running, it looks like the sock is in a different location?

Cannot connect to the Docker daemon at unix:///Users/{username}/.docker/run/docker.sock. Is the docker daemon running?

There are a handful of similar issues posted to Stack Overflow, some of which talk about using sudo (which I’d rather not do), and others talk about creating a new docker group with various command-line incantations to include the user account in the new docker group.

I’m curious if anyone here has run into this recently, and what an “official” workaround or solution might be?


1 Like

Hi @case,

This tutorial does seem to be assuming that you’ll have Docker running on your local system with a socket at the typical default location.

If you know that the socket is in a subdirectory of your home directory on your system, I believe you can set that using the optional host argument inside the provider "docker" block:

provider "docker" {
  host = "unix:///Users/{username}/.docker/run/docker.sock"

I’m afraid I don’t use a Mac myself so I am not familiar with how Docker for Mac is configured, so I’m relying only on what you’ve mentioned in your comment here. Someone else who has more direct experience with using Terraform with Docker for Mac might be able to offer more specific advice, but hopefully the above is enough to get the tutorial working for you.

1 Like

This did the trick, thanks for pointing me in the right direction here @apparentlymart! It would probably be worth updating the tutorial to include this tidbit.