Developing a Cloud Run service locally

Before you deploy a service to Cloud Run, you can develop it locally using a Cloud Run emulator.

Configuring your service for development

To run your service locally, specify your configuration as follows:

  1. Open the Command Palette (press Ctrl/Cmd+Shift+P) and then run the Run on Cloud Run Emulator command.
  2. In the Run/Debug on Cloud Run Emulator dialog, set the specifications for your configuration.

    Cloud Run: Run/Debug Locally UI

Optional: Customizing your configuration

In addition to the settings above, you can specify advanced settings like a service account and environment variables, using the Advanced settings section.

Environment variables

The following environment variables are automatically added to the running containers:

Name Description Example
PORT The port your HTTP server should listen on. 8080
K_SERVICE The name of the Cloud Run service being run. hello-world
K_REVISION The name of the Cloud Run revision being run. hello-world.1
K_CONFIGURATION The name of the Cloud Run configuration that created the revision. hello-world

Running your service locally

  1. After you define your preferred settings, run your service by clicking Run.
  2. Monitor the status of your deployment in the output window.

    After deployment is complete, you can view your running service by opening the URL displayed in the output window.

  3. To view verbose logs, switch to the detailed Cloud Run view in the output window.

    Output pane with "hello-world-5 - Detailed" selected from output channel dropdown

  4. After your session completes, you can use the following contextual menu commands:

    • Open Deployment Logs: Open the application logs of a specific deployment with the Cloud Code Logs Viewer
    • Open Service URL: Open the application service URL of a specific service in a web browser
  5. If have turned off watch mode in your launch configuration and you want to make changes to your application and rebuild and redeploy the application, in the Development sessions pane, pause on the run action and then click Rebuild and redeploy icon Rebuild and redeploy the application.

  6. To stop your deployment, you can click the Stop button in the action bar for your current deployment.

    Action bar for Cloud Run deployment

Storing secrets

If your code includes potentially sensitive data like API keys, passwords, and certificates, it is recommended you store them as secrets. With Cloud Code, you can securely store these secrets in Secret Manager and programmatically fetch them when you need them. For a detailed look at how you can create and manage secrets with Cloud Code, refer to the Secret Manager guide.

Customizing an existing launch.json configuration

To configure how your service is run, you can customize your skaffold.yaml as well as specify the following fields in your .vscode/launch.json:

  • watch: Watches for changes in the workspace and reruns the service. True by default.
  • build: Specify the builder (Docker, buildpacks) to build your images with.
  • image: Specify the name of the image to use.
  • service: Specify the Cloud Run service to use.
  • debug: Specify preferred debug settings such as remote path mapping to map a local path to a path on the remote container.

Getting Support

To send feedback, report issues on GitHub, or ask a question on Stack Overflow.