相关疑难解决方法(0)

如何使用HTTP API从gcr.io Docker注册表中列出图像和标签?

我正在尝试从Node.js中的Google Container Registry(gcr.io)获取可用图像及其标签的列表。

我首先使用google-auto-auth来获取具有scope的令牌https://www.googleapis.com/auth/devstorage.read_write,然后将该令牌交换为gcr.io令牌,如下所示:

axios.get('https://gcr.io/v2/token?service=gcr.io', {
  auth: {
    username: '_token',
    password: token // token I got from `google-auto-auth`
  }
})
Run Code Online (Sandbox Code Playgroud)

然后,我尝试使用此方法来调用v2/_catalog端点:

axios.get('https://gcr.io/v2/_catalog', {
  headers: {
    Authorization: `Bearer ${gcrToken}`
  }
})
Run Code Online (Sandbox Code Playgroud)

我得到以下错误:

{ 
  errors: [ { code: 'DENIED', message: 'Failed to retrieve projects.' } ] 
}
Run Code Online (Sandbox Code Playgroud)

足够公平,它必须提供我的项目ID,但是我应该在哪里提供呢?

只是为了看看我是否还能使其他任何东西正常工作,我尝试了:

axios.get('https://gcr.io/v2/my-project-id/my-image/tags/list', {
  headers: {
    Authorization: `Bearer ${gcrToken}`
  }
})
Run Code Online (Sandbox Code Playgroud)

我得到以下信息:

{ 
  errors: [ 
    { 
      code: 'NAME_INVALID', 
      message: 'Requested repository does not match bearer token resource: …
Run Code Online (Sandbox Code Playgroud)

node.js docker google-cloud-platform docker-registry google-container-registry

5
推荐指数
2
解决办法
1746
查看次数