我的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 on apply:
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命令成功并导致相同的错误。
答案 0 :(得分:3)
使用您的确切配置,它对我来说很成功。见下面的输出:
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:
答案 1 :(得分:0)
在映像资源中,使用docker映像存储库的全名:
resource "docker_image" "ubuntu" {
name = "**docker.io/**ubuntu:precise"
}