# GCP GCR

### 在 Edgegap 中使用 Google 容器注册表

### 您需要随手准备

* [x] 您 GCR 的 GCP 区域
* [x] 您的 GCP 项目名称
* [x] 您为 IAM 用户生成的 JSON 密钥

### 要获取此信息，请前往 GCP 控制台

1. 转到您的项目
2. 转到容器注册表
3. 复制完整的仓库名称

### 拆分完整仓库名称

以此完整仓库为例： **gcr.io/project-name/example**

您的 **仓库** 将是： **gcr.io**

而您的 **镜像** 将是： **project-name/example**

### 生成您的 JSON 密钥文件

请按照 [**GCP 步骤**](https://cloud.google.com/container-registry/docs/advanced-authentication#json-key) 来生成此文件。

{% hint style="warning" %}
请确认您的 `Google 服务账号` 具有管理您的容器注册表的正确权限
{% endhint %}

您将得到一个包含类似内容的文件

```json
{
  "type": "service_account",
  "project_id": "project-name",
  "private_key_id": "12345abcdef12345",
  "private_key": "-----BEGIN PRIVATE KEY-----\n[...]\n-----END PRIVATE KEY-----\n",
  "client_email": "example@project-name.iam.gserviceaccount.com",
  "client_id": "1234567890",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/example%40project-name.iam.gserviceaccount.com"
}
```

### 在 Edgegap 上添加应用

#### **API 示例**

{% hint style="info" %}
用户名始终为 **\_json\_key**
{% endhint %}

```json
{
    [...]
    "docker_repository": "gcr.io",
    "docker_image": "project-name/repository-name",
    "docker_tag": "v1",
    "private_username": "_json_key",
    "private_token": "<JSON 密钥文件内容的 JSON 字符串>",
    [...]
}
```

私有令牌看起来类似于

```json
{
    [...]
    "private_token": "{\"type\": \"service_account\", \"project_id\": \"project-name\", \"private_key_id\": \"12345abcdef12345\", \"private_key\": \"-----BEGIN PRIVATE KEY-----\\n[...]\\n-----END PRIVATE KEY-----\\n\", \"client_email\": \"example@project-name.iam.gserviceaccount.com\", \"client_id\": \"1234567890\", \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\", \"token_uri\": \"https://oauth2.googleapis.com/token\", \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\", \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/example%40project-name.iam.gserviceaccount.com\"}",
    [...]
}
```

#### **来自仪表板**

在我们的仪表板中， **私有注册表令牌** 将是您 **JSON 密钥文件**

**您可以直接复制内容，无需将其转换为字符串**

<figure><img src="/files/b0db964b590e0d6e8179632b605c2bb361a32e0f" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.edgegap.com/zh/docs/tools-and-integrations/container/external-registries/gcp-gcr.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
