Adding container environment variables
When you add environment variables, a new container revision is created. You cannot add environment variables to an existing revision.
- In the management console
, select the folder with your container. - Select Serverless Containers.
- Select the container whose version you want to add an environment variable for.
- Go to the Editor tab.
- In the window that opens, under Image settings, specify the environment variable and click Add. You can add multiple environment variables.
- Click Create revision. A new container revision with the specified environment variables will be created.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To add environment variables, run the command:
Warning
If the previous revision contained environment variables, this command overwrites them.
yc serverless container revision deploy \
--container-name <container_name> \
--image <Docker_image_URL> \
--cores 1 \
--memory 1GB \
--service-account-id <service_account_ID> \
--environment <environment_variables>
Where:
--cores: Number of cores available to the container.--memory: Required memory. The default value is 128 MB.--environment: Environment variables inkey=valueformat. You can specify multiple pairs separated by commas.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To add environment variables:
-
Open the Terraform configuration file and add a list with environment variables named
environmentto theimagesection for theyandex_serverless_containerresource:... resource "yandex_serverless_container" "test-container" { name = "my-container" memory = 256 service_account_id = "ajecvjv1lv01********" image { url = "cr.yandex/yc/test-image:v1" environment = { <key> = "<value>" } } } ...Where
environmentrepresents environment variables inkey="value"format. You can specify more than one pair.For more information about the
yandex_serverless_containerparameters in Terraform, see the relevant Terraform article. -
Check the configuration using this command:
terraform validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planThe terminal will display a list of resources with their parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply -
Confirm the changes: type
yesinto the terminal and press Enter.
You can check the new environment variables using the management console
yc serverless container revision get <revision_ID>
To add an environment variable, use the deployRevision REST API method for the Container resource or the ContainerService/DeployRevision gRPC API call.