If avoiding running a separate registry is your goal, I believe that can be accomplished by skipping using docker_image
altogether and just using docker_container
with an image
argument referring to an image that is already available to the Docker daemon indicated in the provider configuration.
docker_image
retrieves a remote image into the daemon's local image cache, but docker build
writes its result directly into the local image cache of the daemon used for the build process, so as long as both Terraform and docker build
are interacting with the same daemon, Terraform's Docker provider should be able to find and use the cached image without interacting with a registry at all.
For example, you could build an automation pipeline that runs docker build
first, obtains the raw id (hash) of the image that was built, and then runs terraform apply -var="docker_image=$DOCKER_IMAGE"
against a suitable Terraform configuration that can then immediately use that image.
Having such a tight coupling between the artifact build process and the provisioning process does defeat slightly the advantages of the separation, but the capability is there if you need it.