Creating a container
-
In the management console, select the folder where you wish to create your container.
-
Select Serverless Containers.
-
Click Create container.
-
Enter a name and a description for the container. Name format:
- The length can be from 3 to 63 characters.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter. The last character can't be a hyphen.
-
Click Create.
If you don't have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To create a container, run the command:
yc serverless container create --name <container_name>
Result:
id: bba3fva6ka5g********
folder_id: b1gqvft7kjk3********
created_at: "2021-07-09T14:49:00.891Z"
name: my-beta-container
url: https://bba3fva6ka5g********.containers.yandexcloud.net/
status: ACTIVE
You can create a container using the API create method.
With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it by configuration files. They store the infrastructure description in HashiCorp Configuration Language (HCL). Terraform and its providers are distributed under the Mozilla Public License.
For more information about the provider resources, see the documentation on the Terraform site or mirror site.
If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To create a container and a container revision:
Note
If a registry or repository containing the Docker image is not public, you need to specify a service account with permission 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.
-
In the configuration file, describe the parameters of resources that you want to create:
-
name
is the container name. Required parameter. Naming requirements:- The length can be from 3 to 63 characters.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter. The last character can't be a hyphen.
-
memory
: Amount of memory allocated to a container, MB. The default is 128 MB. -
service_account_id
= service account ID. -
url
: Docker image URL in Container Registry.
Example configuration file structure:
provider "yandex" { token = "<OAuth>" cloud_id = "<cloud ID>" folder_id = "<folder ID>" zone = "ru-central1-a" } resource "yandex_serverless_container" "test-container" { name = "<container name>" memory = <memory size> service_account_id = "<service account ID>" image { url = "<Docker image URL>" } }
For more information about the
yandex_serverless_container
resource in Terraform, see the provider documentation. -
-
Make sure that the configuration files are valid.
-
In the command line, go to the directory where you created the configuration file.
-
Run the check using the command:
terraform plan
If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If the configuration contains errors, Terraform will point them out.
-
-
Deploy the cloud resources.
-
If the configuration doesn't contain any errors, run the command:
terraform apply
-
Confirm the resource creation: type
yes
in the terminal and press Enter.
Afterwards, all the necessary resources are created in the specified folder. You can verify that the resources are there and properly configured in the management console or using the following CLI command:
yc serverless container list
-