Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform with docker provider , can't pull the image

Tags:

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

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

I deleted all the existing local images from my system and then run again , and then do docker images i noted that it does pull the image , but still unable to succeed with apply command and results in the same error.

like image 290
Ijaz Ahmad Avatar asked Oct 18 '22 19:10

Ijaz Ahmad


1 Answers

Used your exact config and it was successful for me. See output below:

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:
like image 106
Innocent Anigbo Avatar answered Oct 21 '22 08:10

Innocent Anigbo