Terraform与docker provider,can';不要拉图像

Terraform与docker provider,can';不要拉图像,terraform,Terraform,My terraform config.tf: provider "docker" { host = "tcp://my_dockerhost:2376/" } resource "docker_container" "ubuntu" { name = "foo" image = "${docker_image.ubuntu.latest}" } resource "docker_image" "ubuntu" { name = "ubuntu:precise" }

My terraform config.tf:

 provider "docker" {
   host = "tcp://my_dockerhost:2376/"
 }


resource "docker_container" "ubuntu" {
  name = "foo"
  image = "${docker_image.ubuntu.latest}"
}


resource "docker_image" "ubuntu" {
  name = "ubuntu:precise"
}
适用时的Erorr:

 docker_image.ubuntu: Creating...
 latest: "" => "<computed>"
 name:   "" => "ubuntu:precise"
 Error applying plan:

 1 error(s) occurred:

 docker_image.ubuntu: **Unable to read Docker image into resource: Unable to find or pull image ubuntu:precise**
docker\u image.ubuntu:正在创建。。。
最新版本:“”=>“”
名称:“=>”ubuntu:Precision
应用计划时出错:
发生1个错误:
docker_image.ubuntu:*无法将docker图像读入资源:无法找到或提取图像ubuntu:Precision**

我从我的系统中删除了所有现有的本地映像,然后再次运行,然后执行docker images我注意到它确实拉取了映像,但仍然无法使用apply命令成功,并导致相同的错误。

使用了您的精确配置,对我来说是成功的。见下面的输出:

docker_image.ubuntu: Refreshing state... (ID: sha256:5b117edd0b767986092e9f721ba23649...f53f1f41aff9dd1861c2d4feubuntu:precise)
docker_container.ubuntu: Refreshing state... (ID: 0482ec57dadff257a64815b10ac1d97863844a16852af7326046bb2ce3c8de0a)
aws_key_pair.mykey: Refreshing state... (ID: mykey)
aws_instance.example: Refreshing state... (ID: i-054b71ec0f9fe55bb)
docker_image.ubuntu: Creating...
  latest: "" => "<computed>"
  name:   "" => "ubuntu:precise"
docker_image.ubuntu: Creation complete (ID: sha256:5b117edd0b767986092e9f721ba23649...f53f1f41aff9dd1861c2d4feubuntu:precise)
docker_container.ubuntu: Creating...
  bridge:           "" => "<computed>"
  gateway:          "" => "<computed>"
  image:            "" => "sha256:5b117edd0b767986092e9f721ba2364951b0a271f53f1f41aff9dd1861c2d4fe"
  ip_address:       "" => "<computed>"
  ip_prefix_length: "" => "<computed>"
  log_driver:       "" => "json-file"
  must_run:         "" => "true"
  name:             "" => "foo"
  restart:          "" => "no"
docker_container.ubuntu: Creation complete (ID: a069e59359f19902d75642c584746c70098ed4f76f04d4570ae53f2383774649)

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path:
docker\u image.ubuntu:刷新状态。。。(ID:sha256:5B17EDD0B767986092E9F721BA23649…f53f1f41aff9dd1861c2d4feubuntu:精确)
docker_container.ubuntu:正在刷新状态。。。(ID:0482EC57DADF257A64815B10AC1D97863844A16852AF7326046BB2CE3C8DE0A)
aws\u key\u pair.mykey:正在刷新状态。。。(ID:mykey)
aws_实例。示例:正在刷新状态。。。(ID:i-054b71ec0f9fe55bb)
docker_image.ubuntu:正在创建。。。
最新版本:“”=>“”
名称:“=>”ubuntu:Precision
docker_image.ubuntu:创建完成(ID:sha256:5B17EDD0B767986092E9F721BA23649…F53F1F41AF9DD1861C2D4FEUBUNTU:精确)
docker_container.ubuntu:正在创建。。。
网桥:“”=>“”
网关:“”=>“”
图像:“”=>“sha256:5B17EDD0B767986092E9F721BA2364951B0A271F53F1F41AFF9DD1861C2D4FE”
ip地址:“”=>“”
ip前缀长度:“”=>“”
日志驱动程序:“”=>“json文件”
必须运行:“”=>“true”
名称:“”=>“foo”
重新启动:“”=>“否”
docker_container.ubuntu:创建完成(ID:a069e59359f19902d75642c584746c70098ed4f76f04d4570ae53f2383774649)
申请完成!资源:添加2个,更改0个,销毁0个。
基础结构的状态已保存到路径
在下面需要此状态才能修改和销毁您的
基础设施,所以要保证安全。检查完整状态
使用“地形显示”命令。
状态路径:

在图像资源中,使用docker图像存储库的全名:

resource "docker_image" "ubuntu" {
    name = "**docker.io/**ubuntu:precise"
}

我觉得不错。最有可能的是你的码头设置问题。能否检查docker守护进程是否正在运行,以及是否可以远程登录端口2376?其次,使用它运行最新的terraform。