Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Provider can't connect to Docker daemon in WSL 2 #303

Open
mattwelke opened this issue Oct 31, 2020 · 0 comments
Open

Provider can't connect to Docker daemon in WSL 2 #303

mattwelke opened this issue Oct 31, 2020 · 0 comments

Comments

@mattwelke
Copy link

Terraform Version

Terraform v0.12.29 (using old version intentionally because I'm following a tutorial that references particular modules that don't yet support 0.13)

Affected Resource(s)

n/a

Terraform Configuration Files

versions.tf:

terraform {
  required_version = "~> 0.12"
  required_providers {
    google  = "~> 2.16"
    random  = "~> 2.2"
    docker  = "~> 2.3"
  }
}

providers.tf:

provider "google" {
  credentials = file("account.json")
  project     = var.gcp.project_id
  region      = var.gcp.region
}

provider "docker" {
  host = "tcp://127.0.0.1:2375/"
}

variables.tf:

variable "gcp" {
  type = object({
    project_id = string
    region     = string
  })
}

terraform.tfvars:

gcp = {
  project_id = "REDACTED"
  region     = "us-east1"
}

outputs.tf:

output "addresses" {
  value = {
    gcp1         = module.gcp1.network_address
    gcp2         = module.gcp2.network_address
    loadbalancer = module.loadbalancer.network_address
  }
}

main.tf:

module "gcp1" {
  source     = "scottwinkler/vm/cloud//modules/gcp"
  project_id = var.gcp.project_id
  environment = {
    name             = "GCP 1"
    background_color = "red"
  }
}

module "gcp2" {
  source     = "scottwinkler/vm/cloud//modules/gcp"
  project_id = var.gcp.project_id
  environment = {
    name             = "GCP 2"
    background_color = "blue"
  }
}

module "loadbalancer" {
  source = "scottwinkler/vm/cloud//modules/loadbalancer"
  addresses = [
    module.gcp1.network_address,
    module.gcp2.network_address,
  ]
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://gist.github.com/mattwelke/ce34d58c1281d49930f81caaa257800e

Panic Output

n/a

Expected Behavior

A docker container being created.

Actual Behavior

An error applying Terraform config when it tried to use the Docker provider.

Steps to Reproduce

  1. Start Docker Desktop in Windows, wait til it's ready
  2. Ensure the Docker daemon is reachable from within WSL 2 (ex. run docker ps)
  3. Add Docker provider to config
  4. Run terraform apply

Important Factoids

I ensured I had Docker set up to be useable from within WSL 2 first. I was able to run commands like docker ps:

> docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

But then, when running terraform apply, it displayed that error, saying it couldn't reach the daemon. I tried using the port 2376 instead of 2375 in the Terraform config, but that didn't work. I also tried enabling this option in Docker Desktop in Windows:

image

But this also made no difference (even when using port 2375 in the Terraform config).

I'm using Ubuntu 20.10 in WSL 2.

References

When troubleshooting, I tried the steps in the issue #210, but it didn't help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant