# Creating a container revision

You need to create a new revision:

* When you upload a new Docker image version to [Yandex Container Registry](../../container-registry/index.md).
* When you modify revision settings.

{% note info %}

To ensure the integrity of version links, you cannot update or delete container revisions.

{% endnote %}

If a [registry](../../container-registry/concepts/registry.md) or [repository](../../container-registry/concepts/repository.md) containing the Docker image is not [public](../../container-registry/qa/index.md#public-registry), you need to specify a [service account](../../iam/concepts/users/service-accounts.md) with [permission](../../iam/operations/sa/assign-role-for-sa.md) to download the Docker image in the revision settings. For example, the `container-registry.images.puller` role to the folder or registry containing the Docker image.

If a service account is specified in the revision settings, the user or the service account creating the revision must have the `iam.serviceAccounts.user` role. It confirms the right to use the service account.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) with your [container](../concepts/container.md).
  1. Navigate to **Serverless Containers**.
  1. Select the container whose [revision](../concepts/container.md#revision) you want to create.
  1. Navigate to the **Editor** tab.
  1. Under **Image settings**:
      * Specify the Yandex Container Registry Docker image URL.
      * Additionally specify the revision settings as required:
          * **Command**: Commands the container will run when started. It matches the `ENTRYPOINT` instruction in the Dockerfile.
          * **Arguments**: Matches the `CMD` instruction in the Dockerfile. Specify arguments in `key = value` format. If you do not specify this parameter, the default `CMD` value from the Docker image will be used.

              You can provide multiple arguments to a container. To do this, click **Add**.

          * **Working directory**: Allows you to change the working directory of the container. It matches the `WORKDIR` instruction in the Dockerfile. We recommend setting absolute paths to directories.

  1. Click **Create revision**.

- CLI {#cli}

  To create a [container](../concepts/container.md) [revision](../concepts/container.md#revision), run this command:

  ```bash
  yc serverless container revision deploy \
    --container-name <container_name> \
    --image <Docker_image_URL> \
    --cores 1 \
    --memory 1GB \
    --execution-timeout 30s \
    --service-account-id <service_account_ID> \
    --command '<command_1>','<command_2>' \
    --args '<key_1=value_1>','<key_2=value_2>'
  ```


  Where:
  * `--cores`: Number of cores available to the container.
  * `--memory`: Required memory. The default value is 128 MB.
  * `--execution-timeout`: Timeout. The default value is 3 seconds.
  * `--service-account-id`: [ID of the service account](../../iam/operations/sa/get-id.md) with Docker image pull permissions.
  * `--command`: Commands the container will run when started. Separate them by commas. It matches the `ENTRYPOINT` instruction in the Dockerfile.
  * `--args`: Arguments matching the `CMD` instruction in the Dockerfile. Specify them in `key = value` format separated by commas. If you skip this setting, the default `CMD` value from the Docker image will be used.

  Result:

  ```text
  id: bbajn5q2d74c********
  container_id: bba3fva6ka5g********
  created_at: "2021-07-09T15:04:55.135Z"
  image:
    image_url: cr.yandex/crpd3cicopk7********/test-container:latest
    image_digest: sha256:de8e1dce7ceceeafaae122f7670084a1119c961cd9ea1795eae92bd********
  resources:
    memory: "1073741824"
    cores: "1"
  execution_timeout: 3s
  service_account_id: ajeqnasj95o7********
  status: ACTIVE
  ```

- Terraform {#tf}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the relevant documentation on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../terraform/authentication.md) using the appropriate method.

  In Terraform, each update to the resource settings creates a new [revision](../concepts/container.md#revision).

  To create a revision:
  1. Update the `yandex_serverless_container` resource settings in the configuration file:

     ```hcl
     resource "yandex_serverless_container" "test-container" {
       name               = "<container_name>"
       cores              = "<number_of_cores>"
       memory             = "<memory_size>"
       service_account_id = "<service_account_ID>"
       image {
         url      = "<Docker_image_URL>"
         command  = ["<command_1>","<command_2>"]
         args     = ["<key_1=value_1>","key_2=value_2"]
         work_dir = "<working_directory>"
       }
     }
     ```

     Where:

     * `cores`: Number of cores available to the container.
     * `memory`: Required memory. The default value is 128 MB.
     * `command`: Commands the container will run when started. Separate them by commas. It matches the `ENTRYPOINT` instruction in the Dockerfile.
     * `args`: Arguments matching the `CMD` instruction in the Dockerfile. Specify them in `key = value` format separated by commas. If you skip this setting, the default CMD value from the Docker image will be used.
     * `work_dir`: Allows you to change the working directory of the container. It matches the `WORKDIR` instruction in the Dockerfile. We recommend setting absolute paths to directories.

     For more information about `yandex_serverless_container` properties in Terraform, see [this provider guide](../../terraform/resources/serverless_container.md).

  1. Create the resources:

     1. In the terminal, navigate to the configuration file directory.
     1. Make sure the configuration is correct using this command:
     
        ```bash
        terraform validate
        ```
     
        If the configuration is valid, you will get this message:
     
        ```bash
        Success! The configuration is valid.
        ```
     
     1. Run this command:
     
        ```bash
        terraform plan
        ```
     
        You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
     1. Apply the configuration changes:
     
        ```bash
        terraform apply
        ```
     
     1. Type `yes` and press **Enter** to confirm the changes.

     This will create the revision. You can check the new revision using the [management console](https://console.yandex.cloud) or this [CLI](../../cli/index.md) command:

     ```bash
     yc serverless container revision list
     ```

- API {#api}

  To create a [container](../concepts/container.md) [revision](../concepts/container.md#revision), use the [deployRevision](../containers/api-ref/Container/deployRevision.md) REST API method for the [Container](../containers/api-ref/Container/index.md) resource or the [ContainerService/DeployRevision](../containers/api-ref/grpc/Container/deployRevision.md) gRPC API call.

{% endlist %}