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

CC BY-SA 4.0
2018-10-31T00:25:47.523Z
2018-10-31T00:25:47.523Z
parsley72
<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>

<docker><terraform>
How can I use Docker Hub in Terraform?
parsley72
# How can I use Docker Hub in Terraform?

(Asked by: username_0 on 2018-10-28)

The instructions in Terraform Docker Provider 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 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:
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}"]
}


---

