2

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

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

  1. Define the docker image as a template

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

  1. By terraform init install terraform module and apply the terraform template.

# terraform init

# terraform apply -auto-approve

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.