首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“`terraform”未能安装提供者kreuzwerker/docker

“`terraform”未能安装提供者kreuzwerker/docker
EN

Stack Overflow用户
提问于 2022-02-23 10:21:06
回答 2查看 1.6K关注 0票数 0

main.tf

代码语言:javascript
复制
terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
    }
    google = {
      source = "hashicorp/google"
    }
    random = {
      source = "hashicorp/random"
    }
  }
}

provider "docker" {}

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
  }
}

在执行terraform init时,我面临只下载停靠资源的问题:

代码语言:javascript
复制
Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/google...
- Finding latest version of hashicorp/random...
- Finding latest version of kreuzwerker/docker...
- Installing hashicorp/google v4.11.0...
- Installed hashicorp/google v4.11.0 (signed by HashiCorp)
- Installing hashicorp/random v3.1.0...
- Installed hashicorp/random v3.1.0 (signed by HashiCorp)
╷
│ Error: Failed to install provider
│ 
│ Error while installing kreuzwerker/docker v2.16.0: could not query provider registry for registry.terraform.io/kreuzwerker/docker: failed to retrieve authentication checksums for
│ provider: the request failed after 2 attempts, please try again later: Get
│ "https://github.com/kreuzwerker/terraform-provider-docker/releases/download/v2.16.0/terraform-provider-docker_2.16.0_SHA256SUMS": context deadline exceeded

在遵循这个职位之后,我下载了本地文件,并成功地执行了terraform init,但是运行terraform应用失败,错误如下:

代码语言:javascript
复制
│ Error: Could not load plugin
│ 
│ 
│ Plugin reinitialization required. Please run "terraform init".
│ 
│ Plugins are external binaries that Terraform uses to access and manipulate
│ resources. The configuration provided requires plugins which can't be located,
│ don't satisfy the version constraints, or are otherwise incompatible.
│ 
│ Terraform automatically discovers provider requirements from your
│ configuration, including providers used in child modules. To see the
│ requirements and constraints, run "terraform providers".
│ 
│ failed to instantiate provider "registry.terraform.io/kreuzwerker/docker" to obtain schema: fork/exec
│ .terraform/providers/registry.terraform.io/kreuzwerker/docker/2.16.0/linux_amd64/terraform-provider-docker_2.16.0_linux_amd64.zip: permission denied

系统详细信息:

操作系统: Ubuntu 21.10

Terraform版本尝试了:

  • 1.0.6 https://learn.hashicorp.com/教程中使用的相同版本
  • 1.1.16使用apt

我还推出了另一个码头集装箱,并复制了这个问题,并且我能够用terraform init复制同样的问题。

更新:

代码语言:javascript
复制
gahan@jarvis:~/devOps/test$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/random...
- Finding latest version of kreuzwerker/docker...
- Finding latest version of hashicorp/google...
- Installing hashicorp/google v4.11.0...
- Installed hashicorp/google v4.11.0 (signed by HashiCorp)
- Installing hashicorp/random v3.1.0...
- Installed hashicorp/random v3.1.0 (signed by HashiCorp)
╷
│ Error: Failed to install provider
│ 
│ Error while installing kreuzwerker/docker v2.16.0: could not query provider registry for registry.terraform.io/kreuzwerker/docker: failed to retrieve authentication checksums for provider: the request
│ failed after 2 attempts, please try again later: Get "https://github.com/kreuzwerker/terraform-provider-docker/releases/download/v2.16.0/terraform-provider-docker_2.16.0_SHA256SUMS": net/http: request
│ canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
╵

gahan@jarvis:~/devOps/test$ cat /etc/group | grep docker
docker:x:998:gahan

gahan@jarvis:~/devOps/test$ docker pull python:alpine3.13
alpine3.13: Pulling from library/python
5758d4e389a3: Pull complete 
9292b3ab1647: Pull complete 
35d95eb0acaf: Pull complete 
cfda6539f3f2: Pull complete 
f4471b8ea909: Pull complete 
Digest: sha256:93eb0ba98b15791a071ec8bce2483e670e52c83af51962d3255b4f8f93b52d24
Status: Downloaded newer image for python:alpine3.13
docker.io/library/python:alpine3.13
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-02-27 08:17:33

非常感谢这里的帮助@塔潘和其他社区成员。

由于我遵循了安装后的所有步骤,所以重新迭代权限也是如此。

最后,我还创建了一个码头容器来重新创建问题,在进一步调试时发现,即使使用wget命令报告校验和可以下载,但在处理terraform时,它可能使用其他我还不知道的url/协议,但它与我的ISP Airtel光纤连接有某种冲突。

结果,我使用了翘曲桌面客户端并尝试使用terraform命令,该命令为我工作,没有任何问题。

票数 1
EN

Stack Overflow用户

发布于 2022-02-23 10:48:49

@Gahan,我猜问题是权限问题,如果我没有错,码头需要sudo访问才能运行,而terraform可以正常访问用户。如果您错误地查看下面一行

代码语言:javascript
复制
.terraform/providers/registry.terraform.io/kreuzwerker/docker/2.16.0/linux_amd64/terraform-provider-docker_2.16.0_linux_amd64.zip: permission denied

它显示的是“拒绝许可”。

我想您可以尝试将user+group从sudo更改为本地用户以获取.terraform目录,并进行尝试。

代码语言:javascript
复制
chown <user>:<group> .terraform
chmod 750 .terraform/providers/registry.terraform.io/kreuzwerker/docker/2.16.0/linux_amd64/terraform-provider-docker_2.16.0_linux_amd64.zip

最新情况:

此设置在MacOS中运行良好,我只是尝试使用上面的main.tf内容在对接器中创建ngnix容器,并且能够成功地初始化和应用terraform。我用的是Mac操作系统。Terraform版本- 1.1.1,Docker版本- 4.4.2

接下来,我尝试在ubuntu机器(20.04 LTS)上复制相同的内容,并在运行"terraform apply“时遇到了类似的问题。

错误:

代码语言:javascript
复制
 Error: Error pinging Docker server: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied

经过进一步的调查,我解决了这个问题。

造成问题的主要原因是我们的自定义用户无法执行docker的命令。因此,当terraform试图运行与docker相关的命令时,这将失败。我们可以执行以下步骤来解决这个问题

  1. 如果安装正确,应该有一个停靠组可用。您可以签入/etc/group路径。
代码语言:javascript
复制
$ cat /etc/group
  1. 将您的用户Add添加到停靠组中。在我的例子中,用户名是'tapan1991‘
代码语言:javascript
复制
$ sudo usermod -aG docker $User_Name

Eg : sudo usermod -aG docker tapan1991
  1. 从会话中退出并再次登录
  2. 执行terraform计划/应用命令
代码语言:javascript
复制
$ terraform apply

希望这能帮上忙!

参考资料:在"terraform apply“上单击停靠服务器时出错

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71235127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档