Answers: <p>This can be done with <a href="https://www.terraform.io/docs/providers/docker/d/registry_image.html" rel="nofollow noreferrer">docker_registry_image</a>:</p>
  
  <pre><code>data "docker_registry_image" "ubuntu" {
    name = "ubuntu:latest"
  }
  
  resource "docker_image" "ubuntu" {
    name          = "${data.docker_registry_image.ubuntu.name}"
    pull_triggers = ["${data.docker_registry_image.ubuntu.sha256_digest}"]
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2018-10-31T00:25:47.523Z
Answers: 2018-10-31T00:25:47.523Z
Answers: parsley72
Body: <p>The instructions in <a href="https://www.terraform.io/docs/providers/docker/" rel="nofollow noreferrer">Terraform Docker Provider</a> give the example:</p>
  
  <pre><code># Configure the Docker provider
  provider "docker" {
    host = "tcp://127.0.0.1:2376/"
  }
  
  # Create a container
  resource "docker_container" "foo" {
    image = "${docker_image.ubuntu.latest}"
    name  = "foo"
  }
  
  resource "docker_image" "ubuntu" {
    name = "ubuntu:latest"
  }
  </code></pre>
  
  <p>I'm assuming this is pointing to an on-prem docker source. How do I used <a href="https://hub.docker.com/" rel="nofollow noreferrer">Docker Hub</a> directly?</p>
  
Tags: <docker><terraform>
Title: How can I use Docker Hub in Terraform?
UserDisplayName: parsley72
ThreadText: # How can I use Docker Hub in Terraform?
  
  (Asked by: username_0 on 2018-10-28)
  
  The instructions in [Terraform Docker Provider](https://www.terraform.io/docs/providers/docker/) give the example:
  
  ```
  # Configure the Docker provider
  provider "docker" {
    host = "tcp://127.0.0.1:2376/"
  }
  
  # Create a container
  resource "docker_container" "foo" {
    image = "${docker_image.ubuntu.latest}"
    name  = "foo"
  }
  
  resource "docker_image" "ubuntu" {
    name = "ubuntu:latest"
  }
  
  ```
  
  I'm assuming this is pointing to an on-prem docker source. How do I used [Docker Hub](https://hub.docker.com/) directly?
  
  **Tags:** docker, terraform
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-10-31. Score: 1 | Accepted answer
  
  This can be done with [docker\_registry\_image](https://www.terraform.io/docs/providers/docker/d/registry_image.html):
  
  ```
  data "docker_registry_image" "ubuntu" {
    name = "ubuntu:latest"
  }
  
  resource "docker_image" "ubuntu" {
    name          = "${data.docker_registry_image.ubuntu.name}"
    pull_triggers = ["${data.docker_registry_image.ubuntu.sha256_digest}"]
  }
  
  ```
  
  
  ---
  
  