Develop a Cloud Run service locally in Cloud Code for VS Code

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

Configuring your service for development

If you don't have a.vscode/launch.json file defined, theRun/Debug on Cloud Run Emulator dialog lets you configure your launch andthen saves your settings to.vscode/launch.json. If you have a.vscode/launch.json file configured, you can edit the file directly.

To run your service locally, specify your configuration:

  1. Open the command palette (pressCtrl/Cmd+Shift+P or clickView >Command Palette) and then run theRun on Cloud Run Emulator command.
  2. In the Run/Debug on Cloud Run Emulator dialog, set thespecifications for your configuration:

    • Only locally-installed build tools are available for Cloud RunEmulator
    • ChooseDocker orBuildpacks as your builder and then specify thesource
    • (Optional) To specify any environment variables to pass to the runningcontainers, expandAdvanced Build Settings and then click to specifykey-value pairs.
      NameDescriptionExample
      PORTThe port for the HTTP server to listen on.8080
      K_SERVICEThe name of the Cloud Run service being run.hello-world
      K_REVISIONThe name of the Cloud Run revision being run.hello-world.1
      K_CONFIGURATIONThe name of the Cloud Run configuration that created the revision.hello-world
    • (Optional) To specify Cloud SQL connections, expandAdvanced Service Settings, clickConnections, and then specify oneCloud SQL connection per line.
    • (Optional) Check theMake the service accessible from other devices on the local networkoption.
    • (Optional) If you only want to rebuild and run your service manually,instead of automatically when you make a change, clear theAutomatically re-build and re-run on changes option.

Running your service locally

  1. After you define your preferred settings, run your service by clickingRun.

  2. If prompted,authenticate your credentials to run and debug anapplication locally.

  3. Monitor the status of your deployment in theoutput window.

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

  4. To view verbose logs, switch to the detailed Cloud Run viewin the output window.

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

  5. After your session completes, right-click to use the following commands:

    • View Logs: Open the application logs of a specific deployment with theCloud Code logs explorer.
    • Open URL: Open the application service URL of a specificservice in a web browser.
  6. If you've turned off watch mode in your launch configuration and you want tomake changes to your application and rebuild and redeploy the application,click the Cloud Code status bar and then clickTurn on watch mode.

  7. To stop your deployment, you can click theStop button in the action barfor your current deployment.

    Action bar for Cloud Run deployment

Storing secrets

If your code includes potentially sensitive data like API keys, passwords, andcertificates, storing them as secrets can help secure them. TheCloud Code Secret Manager integration lets you securelystore these secrets and fetch them programmatically. For a detailed look at howyou can create and manage secrets with Cloud Code, seetheSecret Manager guide.

Customizing an existing launch.json configuration

The Cloud Code plugin updates thelaunch.json configuration fileautomatically when you choose a run action. To further customize how yourservice is run, you can specify the following fields in your.vscode/launch.json file:

  • watch: Watches for changes in the workspace and reruns the service. True by default.

    The following sample shows watch set totrue:

    "watch":true,
  • build: Specify the builder(Docker,jibMaven, jibGradle, orbuildpacks)to build your images with.

    The following sample shows a Docker builder:

    "build":{"docker":{"path":"Dockerfile"}},

    The following sample shows a buildpack builder:

    "build":{"buildpacks":{"path":"src/requirements.txt","builder":"gcr.io/buildpacks/builder:v1"}},
  • image: Specify the name of the image to use.

    The following sample shows how to specify an image name:

    "image":"hello-world",
  • service: Specify the Cloud Run service to use.

    The following sample shows how to specify a service name, port, and resourcelimits:

    "service":{"name":"hello-world","containerPort":8080,"resources":{"limits":{"memory":"256Mi"}}},
  • debug: Specify debug settings such as remote path mapping to map a localpath to a path on the remote container.

    The following sample shows a debug section that indicates the source files'location:

    "debug":{"sourceFileMap":{"${workspaceFolder}":"/app"}}

Get Support

To send feedback, report issues onGitHub,or ask a question onStack Overflow.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.