Search code examples
apidockerregistryterraform

terraform provider + docker registry v2 = 404


I am trying to start some containers using terraform, pulling those from my own registry but just can't get past the pinging docker server validation, where I get a fugly: * Error pinging Docker server: API error (404): 404 page not found error.

For better explaining this, I started the registry as docker documentation points out; afterwards pushed an image and tried to apply a very basic .tf configuration using terraform:

docker.tf

# set provider to local registry
provider "docker" {
    host = "http://docker.localhost.com:5000/v2/ubuntu"
}

# create container
resource "docker_container" "test" {
    image = "latest"
    name = "test"
}

I can pull the manifests and the images using a URL like: http://docker.localhost.com:5000/v2/ubuntu/_manifests/latest without much of a problem but when running terraform things go south and all I get is an error.

Checking the registry logs I see this when I run terraform:

`172.*.*.1 - - [04/Apr/2016:18:30:28 +0000] "GET /v2/ubuntu/_ping HTTP/1.1" 404 19 "" "go-dockerclient"`

Tried the same manually using CURL and had a look at the API docs but can't find anywhere _pingbeing implemented so at this point all I'd ask for is a way to bypass this check. Is there a way to do it?

I have no authentication set so far, so this (I believe) is no authentication BS... yet.


Solution

  • The docker host in the docker provider points to the Docker daemon and not a docker registry.

    The go-dockerclient that terraform uses internally is hitting this endpoint of the Docker remote API - https://docs.docker.com/engine/reference/api/docker_remote_api_v1.20/#ping-the-docker-server

    To pull from your registry, you will have to do something like below:

    resource "docker_container" "test" {
        image = "docker.localhost.com:5000/org/some-image:latest"
        name = "test"
    }