Quickstart: Create a Cloud Run Instance

This page shows you how to use Cloud Run to create a Cloud Run instance in a sample container, view its logs, and manage its lifecycle using the gcloud CLI.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Install the Google Cloud CLI.

  3. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  4. To initialize the gcloud CLI, run the following command:

    gcloud init
  5. Create or select a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  6. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  7. Verify that billing is enabled for your Google Cloud project.

  8. Enable the Cloud Run Admin API and Cloud Logging APIs:

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    gcloud services enable run.googleapis.com logging.googleapis.com
  9. Install the Google Cloud CLI.

  10. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  11. To initialize the gcloud CLI, run the following command:

    gcloud init
  12. Create or select a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  13. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  14. Verify that billing is enabled for your Google Cloud project.

  15. Enable the Cloud Run Admin API and Cloud Logging APIs:

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    gcloud services enable run.googleapis.com logging.googleapis.com
  16. To set the default project for your Cloud Run instance:
    gcloud config set project PROJECT_ID
    Replace PROJECT_ID with the name of the project you created for this quickstart.
  17. Ensure you have the gcloud beta component installed:
    gcloud components install beta
  18. Review Cloud Run pricing or estimate costs with the pricing calculator.

Required roles

To get the permissions that you need to complete this quickstart, ask your administrator to grant you the following IAM roles:

For more information about granting roles, see Manage access to projects, folders, and organizations.

You might also be able to get the required permissions through custom roles or other predefined roles.

Create an instance

To create a Cloud Run instance in a sample container using the gcloud CLI:

  1. Run the following command:

    gcloud beta run instances create my-instance \
    --image us-docker.pkg.dev/cloudrun/container/hello \
    --region REGION \
    --port 8080 \
    --no-invoker-iam-check

    Replace REGION with a supported Google Cloud region.

    The --no-invoker-iam-check flag disables IAM invoker authentication, making the instance URL accessible without IAM authentication.

  2. Wait for the instance creation to finish. Upon completion, the command displays output similar to:

    Creating instance...
    Importing container..............done
    Provisioning resources.......done
    Starting instance.....done
    Done.
    Instance [my-instance] has successfully been created.
    
    URL: https://my-instance-PROJECT-NUMBER.REGION.run.app
    
  3. Open the returned URL in your browser to interact with the running container.

View instance logs

To view the logs generated by your Cloud Run instance:

  1. In the Google Cloud console, go to Logs Explorer:

    Go to Logs Explorer

  2. Filter the logs for your specific instance:

    resource.type="cloud_run_instance"
    resource.labels.location="<var>REGION</var>"
    resource.labels.instance_name="my-instance"
    

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

Delete your instance

To stop and delete the Cloud Run instance:

gcloud beta run instances delete my-instance --region REGION

Delete your test project

Deleting your Google Cloud project stops billing for all resources in that project. To release all Google Cloud resources in your project, follow these steps:

    Delete a Google Cloud project:

    gcloud projects delete PROJECT_ID

What's next

For more information on Cloud Run instances, see: