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
-
Install the Google Cloud CLI.
-
Configure the gcloud CLI to use your federated identity.
For more information, see Sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith 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_IDwith your Google Cloud project name.
-
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.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Run Admin API and Cloud Logging APIs:
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. 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 - To set the default project for your Cloud Run instance:
Replace PROJECT_ID with the name of the project you created for this quickstart.gcloud config set project PROJECT_ID
- Ensure you have the
gcloud betacomponent installed:gcloud components install beta
- 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:
- Cloud Run Admin (
roles/run.admin) on the instance - Service Account User (
roles/iam.serviceAccountUser) on the service identity - Logs Viewer (
roles/logging.viewer) on the project
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:
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-checkflag disables IAM invoker authentication, making the instance URL accessible without IAM authentication.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
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:
In the Google Cloud console, go to Logs Explorer:
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: