> For the complete documentation index, see [llms.txt](https://docs.ionos.com/cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ionos.com/cloud/containers/private-container-registry/api-howtos/create_token.md).

# Create a Private Container Registry Token

This section shows you how to create a Private Container Registry token. We assume the following prerequisite:

* [<mark style="color:blue;">A Private Container Registry</mark>](/cloud/containers/private-container-registry/api-howtos/create_registry.md)

In this guide, we used test named repository to create Private Container Registry tokens. Therefore, it is important that you know your Private Container Registry name.

With the `POST` request, you get the Private Container Registry token. You must provide the Private Container Registry ID:

## Request

{% hint style="info" %}
**Note:** The sample `requestID` is `789f8e3c-d5c8-4359-8f85-c200fb89e97c`.
{% endhint %}

```bash
curl --location  \
--request POST 'https://api.ionos.com/containerregistries/registries/:789f8e3c-d5c8-4359-8f85-c200fb89e97c/tokens' \
--header 'Authorization: Bearer ${TOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
  "properties": {
    "name": "test",
    "expiryDate": null,
    "scopes": [
      {
        "name": "*",
        "actions": [
          "pull", "push", "delete"
        ],
        "type": "repository"
      }
    ]
  }
}'
```

## Response

**200 OK - Successfully showed the list of Private Container Registries**

```json
{
    "id": "8fb592e4-494c-11ed-b878-0242ac120002",
    "type": "token",
    "href": "",
    "metadata": {
        "createdBy": "sample@sample.com",
        "createdByUserId": "8hb792e4-494c-11ed-b878-0242ac120002",
        "createdDate": "2022-10-08T15:56:04Z",
        "state": "enabled"
    },
    "properties": {
        "name": "test",
        "scopes": [
            {
                "actions": [
                    "pull",
                    "push",
                    "delete"
                ],
                "name": "*",
                "type": "repository"
            }
        ],
        "expiryDate": null,
        "status": "enabled",
        "credentials": {
            "username": "test",
            "password": "<your-password>"
        }
    }
}
```

### Response fields

| **Field**           | **Type** |                            **Description**                            | **Example**                            |
| ------------------- | :------: | :-------------------------------------------------------------------: | -------------------------------------- |
| **id**              |  string  |                      The id of the created token.                     | `8fb592e4-494c-11ed-b878-0242ac120002` |
| **createdBy**       |  string  |                    The user who created the token.                    | `sample@sample.com`                    |
| **createdByUserId** |  string  |  The ID of the user or service account that initiated the operation.  | `8fb59000-494c-11ed-0242ac120002`      |
| **state**           |  string  |             The status of the Private Container Registry.             | `Running`                              |
| **hostname**        |  string  | The allocated hostname for the particular Private Container Registry. | `demo.cr.de-fra.test.com`              |

{% hint style="info" %}
**Note:**

* Your values will differ from those in the sample code. Your response will have a different `id` for your token.
* Save the **username** and **password** in the response sample for using the [<mark style="color:blue;">**Docker commands**</mark>](https://docs.docker.com/registry/spec/api/).
  {% endhint %}

**409 - Conflict**

```json
{
   "httpStatus": 409,
   "messages": [
       {
           "errorCode": "0",
           "message": "already exists: name is not available"
       }
   ]
}
```

## Docker CLI

If you want to push your local images to docker repository, you need to login to it using:

```bash
docker login [OPTIONS] [SERVER]
```

You need to enter the following options to login:

* **Hostname**
* **Username**
* **Password**

For more information, refer to the the [<mark style="color:blue;">**Docker Commands**</mark>](https://docs.docker.com/registry/spec/api/).

You can push the images to your Private Container Registry by providing all required information. You can query Private Container Registries and look at images manifest, discover tags, delete layers and delete manifest etc. In the Docker API calls:

* **You can use the name of Private Container Registry**
* **Authenticate the API calls with a token**

To know more, explore the [<mark style="color:blue;">**Docker Documentation**</mark>](https://docs.docker.com/registry/spec/api/). The Data Center Designer (DCD) also uses an easy to opt passthrough feature which as discussed uses **Basic Auth** feature, so you do not need to use a separate authentication method for the DCD.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ionos.com/cloud/containers/private-container-registry/api-howtos/create_token.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
