我的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"
}

申请错误:
 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 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 provider的Terraform,无法提取图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41601264/

10-11 22:25
查看更多