I am trying to create and push a docker image to a Google Cloud Registry using Kreuzwerker provide I am able to create the image using the below code (provider settings else where) but when I set the name to the container registry I get an error:
Error: Error pushing docker image: Error response from daemon: Bad parameters and missing X-Registry-Auth: EOF
I am finding the documentation quite poor and lacking examples.
resource "docker_registry_image" "my_project" {
name = "eu.gcr.io/gcp_project/dockerimage:v1"
build {
context = "${path.module}/filepath"
dockerfile = "Dockerfile"
}
}
https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/registry_image
Update:
I ended up using local-exec with a timestamp trigger so the docker command would build and push on each Terraform deployment.
resource "null_resource" "docker_build" {
triggers = {
always_run = timestamp()
}
provisioner "local-exec" {
working_dir = path.module
command = "docker build -t ${local.docker_image} ./my_app/ && docker push ${local.docker_image}"
}
}
How is your provider defined? It should include the registry authentication section.
provider "docker" {
host = "tcp://localhost:2376"
registry_auth {
address = "eu.gcr.io"
config_file = pathexpand("~/.docker/config.json")
}
}
See https://cloud.google.com/container-registry/docs/advanced-authentication on how to create this config.json file if it doesn't exist. You can also find more information on how to configure registry authentication in Terraform Docker Provider at the doc main page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With