> [!WARNING]
>
> **Preview
> --- Cloud Run instances**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

This page describes how to create and manage individually addressable, singleton
Cloud Run instances. Unlike Cloud Run services
that scale based on incoming traffic, an instance is a dedicated compute
container that you manage manually using lifecycle transitions (create, stop,
start, update, delete).

## Supported regions

Cloud Run instances can be created in any of the [supported regions](https://docs.cloud.google.com/run/docs/locations.md.txt),
**except for the following regions**:

- `europe-west1`
- `us-central1`
- `us-east1`

## Before you begin

1. Set up a new project for Cloud Run, as described
   in the [setup](https://docs.cloud.google.com/run/docs/setup.md.txt) page.

2. Enable the Cloud Run Admin API:

       gcloud services enable run.googleapis.com

3. Update `gcloud` components to the latest version:

   ```bash
   gcloud components update
   ```
4. <br />

   If you are under a domain restriction organization policy [restricting](https://docs.cloud.google.com/resource-manager/docs/organization-policy/restricting-domains) unauthenticated invocations for your project, you will need to access your deployed service as described under [Testing private services](https://docs.cloud.google.com/run/docs/triggering/https-request.md.txt#testing-private).

   <br />

### Required roles


To get the permissions that
you need to configure and deploy Cloud Run instances,

ask your administrator to grant you the
following IAM roles:

- [Cloud Run Developer](https://docs.cloud.google.com/iam/docs/roles-permissions/run.md.txt#run.developer) (`roles/run.developer`) on the Cloud Run instance
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the service identity


For a list of IAM roles and permissions that are associated with
Cloud Run, see
[Cloud Run IAM roles](https://docs.cloud.google.com/run/docs/reference/iam/roles.md.txt)
and [Cloud Run IAM permissions](https://docs.cloud.google.com/run/docs/reference/iam/permissions.md.txt).
If your Cloud Run instance interfaces with
Google Cloud APIs, such as Cloud Client Libraries, see the
[service identity configuration guide](https://docs.cloud.google.com/run/docs/configuring/instances/service-identity.md.txt).
For more information about granting roles, see
[deployment permissions](https://docs.cloud.google.com/run/docs/reference/iam/roles.md.txt#additional-configuration)
and [manage access](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

## Create an instance

You can deploy a container image to create a new instance. If you don't provide
a name, one is automatically generated.

### gcloud

To create a new Cloud Run instance using the
`gcloud beta run instances create` command:

```bash
gcloud beta run instances create INSTANCE_NAME \
    --image IMAGE_URL \
    --region REGION
```

To create a new Cloud Run instance using the
`gcloud beta run instances deploy` command:

```bash
gcloud beta run instances deploy INSTANCE_NAME \
    --image IMAGE_URL \
    --region REGION
```

Replace the following:

- `INSTANCE_NAME`: the name of the instance you are creating. The instance name must be unique within your project and region. You cannot create an instance with the same name as an existing Cloud Run instance or service.
- `IMAGE_URL`: a reference to the container image, for example, `us-docker.pkg.dev/cloudrun/container/instances:latest`.
- `REGION`: the Google Cloud region where you are running your instance, for example `europe-west4`.

### Client libraries

To create a new instance from code:

- [Go](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/run/latest/apiv2.md.txt#cloud_google_com_go_run_apiv2_InstancesClient_CreateInstance)
- [Java](https://docs.cloud.google.com/java/docs/reference/google-cloud-run/latest/com.google.cloud.run.v2.InstancesClient.md.txt#com_google_cloud_run_v2_InstancesClient_createInstanceAsync_com_google_cloud_run_v2_CreateInstanceRequest_)
- [Node.js](https://docs.cloud.google.com/nodejs/docs/reference/run/latest/run/v2.instancesclient.md.txt#_google_cloud_run_v2_InstancesClient_createInstance_member_1_)
- [Python](https://docs.cloud.google.com/python/docs/reference/run/latest/google.cloud.run_v2.services.instances.InstancesClient.md.txt#google_cloud_run_v2_services_instances_InstancesClient_create_instance)
- [Ruby](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-run-v2/latest/Google-Cloud-Run-V2-Instances-Client.md.txt#Google__Cloud__Run__V2__Instances__Client_create_instance_instance_)
- [PHP](https://docs.cloud.google.com/php/docs/reference/cloud-run/latest/V2.Client.InstancesClient.md.txt#_Google_Cloud_Run_V2_Client_InstancesClient__createInstance__)
- [.NET](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Run.V2/latest/Google.Cloud.Run.V2.InstancesClient.md.txt#Google_Cloud_Run_V2_InstancesClient_CreateInstance_Google_Cloud_Run_V2_CreateInstanceRequest_Google_Api_Gax_Grpc_CallSettings_)

### REST API

To create a new Cloud Run instance, send a `POST` HTTP
request to the `instances` endpoint.

```bash
curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -d '{
    "containers": [{
      "image": "IMAGE_URL",
      "ports": [{"containerPort": PORT}]
    }],
    "ingress": "INGRESS_TRAFFIC_ALL",
    "invokerIamDisabled": true,
    "timeout": "3600s"
  }' \
  "https://run.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/instances?instance_id=INSTANCE_NAME"
```

Replace the following:

- `IMAGE_URL`: your container image URL.
- `PORT`: the port your container listens on.
- `PROJECT_ID`: your Google Cloud project ID.
- `REGION`: the Google Cloud region of your deployment.
- `INSTANCE_NAME`: the name of your new instance.

After you create an instance, the instance receives a Cloud Run
URL that has the following format:

`https://INSTANCE_NAME-PROJECT_NUMBER.REGION.run.app`

## Update an instance

When you update an instance, such as its container image, port, or environment
variables, the instance is restarted.

> [!CAUTION]
> **Caution:** Cloud Run instances don't have persistent disk storage. If you need to preserve your files and data, save them to an external storage before updating.

### gcloud

To update a Cloud Run instance using the
`gcloud beta run instances update` command:

```bash
gcloud beta run instances update INSTANCE_NAME \
    --image NEW_IMAGE_URL \
    --region REGION
```

To update a Cloud Run instance using the
`gcloud beta run instances deploy` command:

```bash
gcloud beta run instances deploy INSTANCE_NAME \
    --image IMAGE_URL \
    --region REGION
```

### REST API

To update a Cloud Run instance config from the API, send a
`PATCH` HTTP request to the instance URI endpoint.

```bash
curl -H "Content-Type: application/json" \
  -X PATCH \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -d '{template: {containers: [{image: "IMAGE_URL"}]}}' \
  "https://run.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/instances/INSTANCE_NAME"
```

## Stop an instance

Use the stop command or method to stop a running Cloud Run
instance.

> [!CAUTION]
> **Caution:** Stopping an instance terminates the active container runtime, deleting all in-memory files and unpersisted system state. If you need to preserve your files and data, save them to an external storage before stopping.

### gcloud

To stop an instance:

```bash
gcloud beta run instances stop INSTANCE_NAME \
    --region REGION
```

### Client libraries

To stop a running instance from code:

- [Go](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/run/latest/apiv2.md.txt#cloud_google_com_go_run_apiv2_InstancesClient_StopInstance)
- [Java](https://docs.cloud.google.com/java/docs/reference/google-cloud-run/latest/com.google.cloud.run.v2.InstancesClient.md.txt#com_google_cloud_run_v2_InstancesClient_stopInstanceAsync_com_google_cloud_run_v2_StopInstanceRequest_)
- [Node.js](https://docs.cloud.google.com/nodejs/docs/reference/run/latest/run/v2.instancesclient.md.txt#_google_cloud_run_v2_InstancesClient_stopInstance_member_1_)
- [Python](https://docs.cloud.google.com/python/docs/reference/run/latest/google.cloud.run_v2.services.instances.InstancesClient.md.txt#google_cloud_run_v2_services_instances_InstancesClient_stop_instance)
- [Ruby](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-run-v2/latest/Google-Cloud-Run-V2-Instances-Client.md.txt#Google__Cloud__Run__V2__Instances__Client_stop_instance_instance_)
- [PHP](https://docs.cloud.google.com/php/docs/reference/cloud-run/latest/V2.Client.InstancesClient.md.txt#_Google_Cloud_Run_V2_Client_InstancesClient__stopInstance__)
- [.NET](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Run.V2/latest/Google.Cloud.Run.V2.InstancesClient.md.txt#Google_Cloud_Run_V2_InstancesClient_StopInstance_Google_Cloud_Run_V2_StopInstanceRequest_Google_Api_Gax_Grpc_CallSettings_)

### REST API

To stop an instance, send a `POST` HTTP request with the `:stop` decorator:

```bash
curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  "https://run.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/instances/INSTANCE_NAME:stop"
```

## Start or restart an instance

Use the start command or method to start up a stopped instance, or force a
restart on an existing instance.

### gcloud

To start or restart an instance:

```bash
gcloud beta run instances start INSTANCE_NAME \
    --region REGION
```

### Client libraries

To start a stopped instance from code:

- [Go](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/run/latest/apiv2.md.txt#cloud_google_com_go_run_apiv2_InstancesClient_StartInstance)
- [Java](https://docs.cloud.google.com/java/docs/reference/google-cloud-run/latest/com.google.cloud.run.v2.InstancesClient.md.txt#com_google_cloud_run_v2_InstancesClient_startInstanceAsync_com_google_cloud_run_v2_StartInstanceRequest_)
- [Node.js](https://docs.cloud.google.com/nodejs/docs/reference/run/latest/run/v2.instancesclient.md.txt#_google_cloud_run_v2_InstancesClient_startInstance_member_1_)
- [Python](https://docs.cloud.google.com/python/docs/reference/run/latest/google.cloud.run_v2.services.instances.InstancesClient.md.txt#google_cloud_run_v2_services_instances_InstancesClient_start_instance)
- [Ruby](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-run-v2/latest/Google-Cloud-Run-V2-Instances-Client.md.txt#Google__Cloud__Run__V2__Instances__Client_start_instance_instance_)
- [PHP](https://docs.cloud.google.com/php/docs/reference/cloud-run/latest/V2.Client.InstancesClient.md.txt#_Google_Cloud_Run_V2_Client_InstancesClient__startInstance__)
- [.NET](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Run.V2/latest/Google.Cloud.Run.V2.InstancesClient.md.txt#Google_Cloud_Run_V2_InstancesClient_StartInstance_Google_Cloud_Run_V2_StartInstanceRequest_Google_Api_Gax_Grpc_CallSettings_)

### REST API

To start an instance, send a `POST` HTTP request with the `:start` decorator:

```bash
curl -X POST \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  "https://run.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/instances/INSTANCE_NAME:start"
```

## View the list of instances in your project

You can view all active and inactive instances in your project.

### gcloud

To list the instances in a specific region:

```bash
gcloud beta run instances list \
    --region REGION
```

Replace `REGION` with the Google Cloud region
where you are running your instance.

### Client libraries

To list active and inactive instances from code:

- [Go](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/run/latest/apiv2.md.txt#cloud_google_com_go_run_apiv2_InstancesClient_ListInstances)
- [Java](https://docs.cloud.google.com/java/docs/reference/google-cloud-run/latest/com.google.cloud.run.v2.InstancesClient.md.txt#com_google_cloud_run_v2_InstancesClient_listInstances_com_google_cloud_run_v2_ListInstancesRequest_)
- [Node.js](https://docs.cloud.google.com/nodejs/docs/reference/run/latest/run/v2.instancesclient.md.txt#_google_cloud_run_v2_InstancesClient_listInstances_member_1_)
- [Python](https://docs.cloud.google.com/python/docs/reference/run/latest/google.cloud.run_v2.services.instances.InstancesClient.md.txt#google_cloud_run_v2_services_instances_InstancesClient_list_instances)
- [Ruby](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-run-v2/latest/Google-Cloud-Run-V2-Instances-Client.md.txt#Google__Cloud__Run__V2__Instances__Client_list_instances_instance_)
- [PHP](https://docs.cloud.google.com/php/docs/reference/cloud-run/latest/V2.Client.InstancesClient.md.txt#_Google_Cloud_Run_V2_Client_InstancesClient__listInstances__)
- [.NET](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Run.V2/latest/Google.Cloud.Run.V2.InstancesClient.md.txt#Google_Cloud_Run_V2_InstancesClient_ListInstances_Google_Cloud_Run_V2_ListInstancesRequest_Google_Api_Gax_Grpc_CallSettings_)

### REST API

To retrieve a list of instances, send a `GET` HTTP request:

```bash
curl -X GET \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  "https://run.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/instances"
```

## View instance details

Use the describe command or method to view configuration details and current
status.

### gcloud

To describe an instance:

```bash
gcloud beta run instances describe INSTANCE_NAME \
    --region REGION
```

### Client libraries

To view instance configuration details and status from code:

- [Go](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/run/latest/apiv2.md.txt#cloud_google_com_go_run_apiv2_InstancesClient_GetInstance)
- [Java](https://docs.cloud.google.com/java/docs/reference/google-cloud-run/latest/com.google.cloud.run.v2.InstancesClient.md.txt#com_google_cloud_run_v2_InstancesClient_getInstance_com_google_cloud_run_v2_GetInstanceRequest_)
- [Node.js](https://docs.cloud.google.com/nodejs/docs/reference/run/latest/run/v2.instancesclient.md.txt#_google_cloud_run_v2_InstancesClient_getInstance_member_1_)
- [Python](https://docs.cloud.google.com/python/docs/reference/run/latest/google.cloud.run_v2.services.instances.InstancesClient.md.txt#google_cloud_run_v2_services_instances_InstancesClient_get_instance)
- [Ruby](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-run-v2/latest/Google-Cloud-Run-V2-Instances-Client.md.txt#Google__Cloud__Run__V2__Instances__Client_get_instance_instance_)
- [PHP](https://docs.cloud.google.com/php/docs/reference/cloud-run/latest/V2.Client.InstancesClient.md.txt#_Google_Cloud_Run_V2_Client_InstancesClient__getInstance__)
- [.NET](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Run.V2/latest/Google.Cloud.Run.V2.InstancesClient.md.txt#Google_Cloud_Run_V2_InstancesClient_GetInstance_Google_Cloud_Run_V2_GetInstanceRequest_Google_Api_Gax_Grpc_CallSettings_)

### REST API

To describe an instance, send a `GET` HTTP request:

```bash
curl -X GET \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  "https://run.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/instances/INSTANCE_NAME"
```

## Delete an instance

Delete an instance to permanently remove its configuration, metadata, public
direct URL mapping, and identity roles from your project.

> [!CAUTION]
> **Caution:** After deletion, the instance is removed forever and cannot be started or recovered.

### gcloud

To delete an instance:

```bash
gcloud beta run instances delete INSTANCE_NAME \
    --region REGION
```

### Client libraries

To delete an instance from code:

- [Go](https://docs.cloud.google.com/go/docs/reference/cloud.google.com/go/run/latest/apiv2.md.txt#cloud_google_com_go_run_apiv2_InstancesClient_DeleteInstance)
- [Java](https://docs.cloud.google.com/java/docs/reference/google-cloud-run/latest/com.google.cloud.run.v2.InstancesClient.md.txt#com_google_cloud_run_v2_InstancesClient_deleteInstanceAsync_com_google_cloud_run_v2_DeleteInstanceRequest_)
- [Node.js](https://docs.cloud.google.com/nodejs/docs/reference/run/latest/run/v2.instancesclient.md.txt#_google_cloud_run_v2_InstancesClient_deleteInstance_member_1_)
- [Python](https://docs.cloud.google.com/python/docs/reference/run/latest/google.cloud.run_v2.services.instances.InstancesClient.md.txt#google_cloud_run_v2_services_instances_InstancesClient_delete_instance)
- [Ruby](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-run-v2/latest/Google-Cloud-Run-V2-Instances-Client.md.txt#Google__Cloud__Run__V2__Instances__Client_delete_instance_instance_)
- [PHP](https://docs.cloud.google.com/php/docs/reference/cloud-run/latest/V2.Client.InstancesClient.md.txt#_Google_Cloud_Run_V2_Client_InstancesClient__deleteInstance__)
- [.NET](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Run.V2/latest/Google.Cloud.Run.V2.InstancesClient.md.txt#Google_Cloud_Run_V2_InstancesClient_DeleteInstance_Google_Cloud_Run_V2_DeleteInstanceRequest_Google_Api_Gax_Grpc_CallSettings_)

### REST API

To delete an instance, send a `DELETE` HTTP request:

```bash
curl -X DELETE \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  "https://run.googleapis.com/v2/projects/PROJECT_ID/locations/REGION/instances/INSTANCE_NAME"
```

## What's next

- To view the logging transactions for your instances, see [Logging and viewing logs in Cloud Run](https://docs.cloud.google.com/run/docs/logging.md.txt#viewing-logs-cloud-logging).
- Configure your Cloud Run instance:
  - [Memory limits](https://docs.cloud.google.com/run/docs/configuring/instances/memory-limits.md.txt)
  - [CPU limits](https://docs.cloud.google.com/run/docs/configuring/instances/cpu.md.txt)
  - [Container port and entrypoint](https://docs.cloud.google.com/run/docs/configuring/instances/containers.md.txt)
  - [Environment variables](https://docs.cloud.google.com/run/docs/configuring/instances/environment-variables.md.txt)
  - [Volume mounts](https://docs.cloud.google.com/run/docs/configuring/instances/cloud-storage-volume-mounts.md.txt)
  - [Container health check](https://docs.cloud.google.com/run/docs/configuring/instances/healthchecks.md.txt)
  - [Secrets](https://docs.cloud.google.com/run/docs/configuring/instances/secrets.md.txt)
  - [Service identity](https://docs.cloud.google.com/run/docs/configuring/instances/service-identity.md.txt)
  - [Default URL](https://docs.cloud.google.com/run/docs/configuring/instances/default-url.md.txt)
  - [Restart policy](https://docs.cloud.google.com/run/docs/configuring/instances/restart-policy.md.txt)
  - [IAP](https://docs.cloud.google.com/run/docs/securing/identity-aware-proxy-cloud-run.md.txt)