Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to Authenticate Official Docker Hub Registry and Access a Private Image #561

Open
justurbo opened this issue Jun 7, 2023 · 2 comments

Comments

@justurbo
Copy link

justurbo commented Jun 7, 2023

I have been trying to authenticate and access the latest tag of a private Docker Hub registry image without any luck for a couple of days now.

provider "docker" {
  host = "unix:///var/run/docker.sock"

  registry_auth {
    address  = "index.docker.io"
    username = var.docker_username
    password = var.docker_password
  }
}

data "docker_registry_image" "frontend" {
  name = "<username>/<image_name>:<image_tag>"
}

resource "docker_image" "frontend" {
  name          = data.docker_registry_image.frontend.name
  pull_triggers = [data.docker_registry_image.frontend.sha256_digest]
}

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Got error when attempting to fetch image version <username>/<image_name>:<image_tag> from registry: Got bad response from registry: 401 Unauthorized
│ 
│   with module.kubernetes.data.docker_registry_image.frontend,
│   on modules/kubernetes/docker.tf line 29, in data "docker_registry_image" "frontend":
│   29: data "docker_registry_image" "frontend" {

I've replaced real parameters with /<image_name>:<image_tag> for demonstration purposes.

I've tried https://index.docker.io/v1/, registry-1.docker.io, registry.hub.docker.com, and many other registries without any luck. It's getting frustrating at this point.

Has anybody had any luck with pulling official Docker Hub private images?

@thebearingedge
Copy link

Curious about this as well. I've had trouble using the full docker.io/some-namespace/some-image:tag.

example:

# works fine
data "docker_registry_image" "coredns" {
  name = "coredns/coredns:1.11.1"
}

# doesn't work even though `docker pull` works on command line
data "docker_registry_image" "coredns" {
  name = "docker.io/coredns/coredns:1.11.1"
}

contrast with ghcr.io/some-namespace/some-image:tag working fine. Is there some special behavior with docker.io is involved?

@hylowaker
Copy link

hylowaker commented Oct 26, 2023

Try setting your registry to registry.hub.docker.com, then run docker login registry.hub.docker.com before planning.

Still, I have no idea why docker.io with docker login doesn't work but registry.hub.docker.com with docker login registry.hub.docker.com works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants