<p>Yes, As we write terraform template is correct.
When you use terraform apply it will check local docker image list if it doesn't exit it will go to find registry as you define docker image.</p>

<p>If you don't want a pull image from the internet you can try the below steps. But at least you should have a base docker image of any Linux distribution.</p>

<ol>
<li>Create a Dockerfile. </li>
<li>Build Dockerfile as below command</li>
</ol>

<p><code># docker build -t image_name -f Dockerfile</code></p>

<ol start="3">
<li>Define the docker image as a template</li>
</ol>

<p><code>resource "docker_container" "my_service" {
  image = "image_name"
  name  = "my-service"
}</code></p>

<ol start="4">
<li>By <strong>terraform init</strong> install terraform module and apply the terraform template.</li>
</ol>

<p><code># terraform init</code></p>

<p><code># terraform apply -auto-approve</code></p>

CC BY-SA 4.0
2020-04-16T18:24:49.280Z
2020-04-16T18:24:49.280Z
Arvind Rawat
<p>Is it possible to use docker images in Terraform that are <strong>not hosted in a registry</strong> but in the local Docker storage?</p>

<p>I'd like to have a resource like the following where <strong>no pull</strong> is performed on the image if it exists locally.</p>

<pre><code>resource "docker_container" "my_service" {
  image = "my_locally_built_image_name"
  name  = "my-service"
}
</code></pre>

<docker><terraform><docker-registry>
Referencing locally built Docker images in Terraform
dev
# Referencing locally built Docker images in Terraform

(Asked by: username_0 on 2020-04-13)

Is it possible to use docker images in Terraform that are not hosted in a registry but in the local Docker storage?
I'd like to have a resource like the following where no pull is performed on the image if it exists locally.
resource "docker_container" "my_service" {
  image = "my_locally_built_image_name"
  name  = "my-service"
}

**Tags:** docker, terraform, docker-registry


---

## 1 answers

### Answer by username_1 on 2020-04-16. Score: 3 | Accepted answer

Yes, As we write terraform template is correct.
When you use terraform apply it will check local docker image list if it doesn't exit it will go to find registry as you define docker image.

If you don't want a pull image from the internet you can try the below steps. But at least you should have a base docker image of any Linux distribution.

1. Create a Dockerfile.
2. Build Dockerfile as below command

`# docker build -t image_name -f Dockerfile`

3. Define the docker image as a template

`resource "docker_container" "my_service" {
image = "image_name"
name = "my-service"
}`

4. By **terraform init** install terraform module and apply the terraform template.

`# terraform init`

`# terraform apply -auto-approve`


---

