GithubHelp home page GithubHelp logo

Comments (18)

theCrius avatar theCrius commented on July 26, 2024 10

Hey, thanks for the quick reply.

When running terraform init I get this ouput:

Initializing provider plugins...
- Reusing previous version of kreuzwerker/docker from the dependency lock file
- Using previously-installed kreuzwerker/docker v2.13.0

However, I checked the "show terminal" button on the tutorial I was following and noticed that in the sandbox, the commands are working. So I checked the main.tf files in there and noticed that it's different from the one written in the tutorial itself.

The main.tf file that the sandbox terminal uses is:

terraform {
  required_providers {
    docker = {
      source = "kreuzwerker/docker"
    }
  }
  required_version = ">= 0.13"
}

resource "docker_image" "nginx" {
  name = "nginx:latest"
}

resource "docker_container" "nginx" {
  image = docker_image.nginx.latest
  name  = "tutorial"
  ports {
    internal = 80
    external = 80
  }
}

So I tried starting from that one and making just some small changes. ports -> external set to 8000. Not specifying a version for kreuzwerker/docker is downloading already the latest version (I suppose) but just in case I added that as well.

The final version of the file is this one:

terraform {
  required_providers {
    docker = {
      source = "kreuzwerker/docker"
      version = "2.13.0"
    }
  }
  required_version = ">= 0.13"
}

resource "docker_image" "nginx" {
  name = "nginx:latest"
}

resource "docker_container" "nginx" {
  image = docker_image.nginx.latest
  name  = "tutorial"
  ports {
    internal = 80
    external = 8000
  }
}

I cleaned up everything except the main.tf file and run again terraform init and terraform apply and it works without a fuss.
I also tested by removing the option Expose daemon on tcp://localhost:2375 without TLS from Docker Engine and again, cleaning everything and running again init and apply and it works flawlessly.

I guess the problem was this snippet:

provider "docker" {
  host    = "npipe:////.//pipe//docker_engine"
}

But why it was there and it's a problem, I don't know.

Is there a way to reach the writers of the tutorial to tell them to update the content? I can do it myself If it's an open source project as well.

from terraform-provider-docker.

sanzog03 avatar sanzog03 commented on July 26, 2024 2

make sure that the docker is running (use docker ps) before terraform apply. .

from terraform-provider-docker.

theCrius avatar theCrius commented on July 26, 2024 1

Hi there, sorry for barging in after this one was closed but I can't seem to figure out a solution to this issue.

I started from here which was the exact problem I had: hashicorp/terraform-provider-docker#180

But I see that that repo is closed now, for some reason. The solution suggested there, is not working as of today on a fresh installation of terraform and docker. So I decided to try the docker port open instead, even if it's a security issue. I'm just testing locally after all, no big deal.

If you think that there will be a better place to post this, please link it for me.

I'm following this tutorial: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/gcp-get-started
And I altered my main.tf file to this:

terraform {
  required_providers {
    docker = {
      source = "kreuzwerker/docker"
      version = "~> 2.7"
    }
  }
}

provider "docker" {
  # host    = "npipe:////.//pipe//docker_engine"
  host = "tcp://127.0.0.1:2375/"
}

resource "docker_image" "nginx" {
  name         = "nginx:latest"
  keep_locally = false
}

resource "docker_container" "nginx" {
  image = docker_image.nginx.latest
  name  = "tutorial"
  ports {
    internal = 80
    external = 8000
  }
}

Despite that, it output an error:

╷
│ Error: Error pinging Docker server: Cannot connect to the Docker daemon at tcp://127.0.0.1:2375/. Is the docker daemon running?
│
│   with provider["registry.terraform.io/kreuzwerker/docker"],
│   on main.tf line 10, in provider "docker":
│   10: provider "docker" {
│
╵

Even if I have the ports open and the docker engine running. I have docker installed and running from the windows host and I already use it successfully while creating images/containers directly with the docker and docker compose commands from inside the WSL distro (ubuntu 20.x in my case).

from terraform-provider-docker.

theCrius avatar theCrius commented on July 26, 2024 1

Thanks @mavogel, I had already wrote a feedback specifying the issue the other day. I guessed that that could have been one of the channels anyway :)

Have a good weekend!

from terraform-provider-docker.

littleccguy avatar littleccguy commented on July 26, 2024 1

I replied in the feedback as well. I just removed
provider "docker" { host = "npipe:////.//pipe//docker_engine" }
and it worked for me

from terraform-provider-docker.

NDPsss avatar NDPsss commented on July 26, 2024 1

I had a problem with the lab and found this thread. Every time problem was with this part

provider "docker" {
  host    = "npipe:////.//pipe//docker_engine"
}

I ran docker from Win start menu and after terraform apply I got the error docker
Error: Error initializing Docker client: protocol not available │ │ with provider["registry.terraform.io/kreuzwerker/docker"], │ on main.tf line 10, in provider "docker": │ 10: provider "docker" {}

Then I start docker with docker run -d -p 80:80 docker/getting-started and after that the protocol became available.

The part that docker has be to running is missed in the description of the lab.

from terraform-provider-docker.

ladvey avatar ladvey commented on July 26, 2024 1

I replied in the feedback as well. I just removed
provider "docker" { host = "npipe:////.//pipe//docker_engine" }
and it worked for me

This worked for me as well!

from terraform-provider-docker.

adoublef avatar adoublef commented on July 26, 2024 1

Hey all, hoping someone can try help. I am having a similar issue with my docker provider not working via Terraform Cloud.

I have been able to get this working locally but when I tried Terraform Cloud (in order to setup GitHub actions) I am now getting errors.

I am not using GCP and trying to push to docker registry instead, unsure if that matters.

I am using v3.0.1 of the plug-in.
I am using debian as my WSL2 distro

I have tried to check tcp://localhost without TLS and I have tried to set the host explicitly with no luck.

Terraform v1.4.0
on linux_amd64
Initializing plugins and modules...

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Error pinging Docker server: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
│ 
│   with module.docker.provider["registry.terraform.io/kreuzwerker/docker"],
│   on modules/docker/main.tf line 10, in provider "docker":
│   10: provider "docker" {

from terraform-provider-docker.

Verayth avatar Verayth commented on July 26, 2024 1

Reconfiguring docker in WSL2 to listen on port 2375 worked for me:
https://stackoverflow.com/a/63417004/4479786

from terraform-provider-docker.

mattwelke avatar mattwelke commented on July 26, 2024

I fixed this. And usually I leave a comment when I do. Really disappointed that I didn't though because now I don't remember how I did. xD

I think what happened was I misunderstood how Docker is meant to be used from within WSL 2. I installed it in the Linux distro. I didn't use Docker Desktop in Windows (which makes Docker available for use from within WSL 2 as long as Windows programs are on the path - which is the default setting for WSL 2).

And I think when I used the installation of Docker that was done from the host side in Windows 10 using Docker Desktop, it worked.

from terraform-provider-docker.

mavogel avatar mavogel commented on July 26, 2024

What a pity. If you find out/remember the steps how to fix it, then please update here and we'll add it to the documentation.

from terraform-provider-docker.

mattwelke avatar mattwelke commented on July 26, 2024

@mavogel Once I typed it all out, I remembered it. That's exactly what it was. I would consider this issue closed. As far as I know, it's just an issue with how I was using Docker, which of course let to an issue with this provider trying to use Docker.

from terraform-provider-docker.

mavogel avatar mavogel commented on July 26, 2024

Alright, thanks for the update.

from terraform-provider-docker.

mavogel avatar mavogel commented on July 26, 2024

Hi @theCrius , no worries. We're happy to help. Could you update to the latest version ~> 2.13.0 and try again?
Unfortunately, I don't have a windows machine to test here yet (it's in progress)

from terraform-provider-docker.

mavogel avatar mavogel commented on July 26, 2024

@theCrius I asked internally what's the best way to update this page and will come back to you :) THanks for reporting this. I'm also interested in having the tutorials work

from terraform-provider-docker.

theCrius avatar theCrius commented on July 26, 2024

Good to know @mavogel, let me know if I can help in any way. My office's laptop run on windows so I can run tests if needed.

My experience with Terraform is not vast but I'm quite experienced with devops works anyway (dockers, kubernetes, jenkins, etc) so, as much as I can, I'll gladly help.

from terraform-provider-docker.

mavogel avatar mavogel commented on July 26, 2024

@theCrius , here the internal response:

I'm being told the feedback link at the bottom of the tutorial is the best place to report this, but also that the Learn team is aware of the issue and is working on it.

Thanks for reporting the issue, and if you feel contributing to this project let me know :)

from terraform-provider-docker.

sterlp avatar sterlp commented on July 26, 2024

same here, windows 11 using WSL. The problem is, that "http://127.0.0.1:2375/_ping" is not reachable from windows but in the WSL. Not sure if it is a terraform issue in itself.

But docker info works from windows and also all other commands concerning docker; so I am not sure if maybe the plugin has an issue; including the VS Code docker integration.

\learn-terraform-docker-container> terraform.exe apply
╷
╷│ Error: Error pinging Docker server: error during connect: Get "http://127.0.0.1:2375/_ping": dial tcp 127.0.0.1:2375: connectex: No connection could be made because the target machine actively refused it.
│
│   with provider["registry.terraform.io/kreuzwerker/docker"],
│   on main.tf line 10, in provider "docker":
│   10: provider "docker" {
│
╵
\learn-terraform-docker-container> docker ps --all
CONTAINER ID   IMAGE         COMMAND    CREATED          STATUS                      PORTS     NAMES4d8fd97434cf   hello-world   "/hello"   9 minutes ago    Exited (0) 9 minutes ago              mystifying_raman

from terraform-provider-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.