Click on the error to see the stack trace details, noting the function calls made just prior to the error.
Use Cloud Logging to review the sequence of operations leading to the problem, including error messages that are not included in the Error Reporting console because of a lack of a recognized error stack trace:
Select Cloud Run Revision > hello-service from the first drop-down box. This will filter the log entries to those generated by your service.
Read more about viewing logs in Cloud Run
If this is an established service, known to work, there will be a previous revision of the service on Cloud Run. This tutorial uses a new service with no previous versions, so you cannot do a rollback.
However, if you have a service with previous versions you can roll back to, follow Viewing revision details to extract the container name and configuration details necessary to create a new working deployment of your service.
Using the details you obtained previously, confirm the problem consistently occurs under test conditions.
Send the same HTTP request by trying it out again, and see if the same error and details are reported. It may take some time for error details to show up.
Because the sample service in this tutorial is read-only and doesn't trigger any complicating side effects, reproducing errors in production is safe. However, for many real services, this won't be the case: you may need to reproduce errors in a test environment or limit this step to local investigation.
Reproducing the error establishes the context for further work. For example, if developers cannot reproduce the error further investigation may require additional instrumentation of the service.
Root cause analysis is an important step in effective troubleshooting to ensure you fix the problem instead of a symptom.
Previously in this tutorial, you reproduced the problem on Cloud Run which confirms the problem is active when the service is hosted on Cloud Run. Now reproduce the problem locally to determine if the problem is isolated to the code or if it only emerges in production hosting.
If you have not used Docker CLI locally with Container Registry, authenticate it with gcloud:
gcloudauthconfigure-docker
For alternative approaches see Container Registry authentication methods.
If the most recently used container image name is not available, the service description has the information of the most recently deployed container image:
gcloudrunservicesdescribehello-service
Find the container image name inside the spec
object. A more targeted command can directly retrieve it:
gcloudrunservicesdescribehello-service\--format="value(spec.template.spec.containers.image)"
This command reveals a container image name such as gcr.io/PROJECT_ID/hello-service
.
Pull the container image from the Container Registry to your environment, this step might take several minutes as it downloads the container image:
dockerpullgcr.io/PROJECT_ID/hello-service
Later updates to the container image that reuse this name can be retrieved with the same command. If you skip this step, the docker run
command below pulls a container image if one is not present on the local machine.
Run locally to confirm the problem is not unique to Cloud Run:
PORT=8080&&dockerrun--rm-ePORT=$PORT-p9000:$PORT\gcr.io/PROJECT_ID/hello-service
Breaking down the elements of the command above,
PORT
environment variable is used by the service to determine the port to listen on inside the container.run
command starts the container, defaulting to the entrypoint command defined in the Dockerfile or a parent container image.--rm
flag deletes the container instance on exit.-e
flag assigns a value to an environment variable. -e PORT=$PORT
is propagating the PORT
variable from the local system into the container with the same variable name.-p
flag publishes the container as a service available on localhost at port 9000. Requests to localhost:9000 will be routed to the container on port 8080. This means output from the service about the port number in use will not match how the service is accessed.gcr.io/PROJECT_ID/hello-service
is a container image tag
, a human-readable label for a container image's sha256 hash identifier. If not available locally, docker attempts to retrieve the image from a remote registry.In your browser, open http://localhost:9000. Check the terminal output for error messages that match those on {ops_name}}.
If the problem is not reproducible locally, it may be unique to the Cloud Run environment. Review the Cloud Run troubleshooting guide for specific areas to investigate.
In this case the error is reproduced locally.
Now that the error is doubly-confirmed as persistent and caused by the service code instead of the hosting platform, it's time to investigate the code more closely.
For purposes of this tutorial it is safe to assume the code inside the container and the code in the local system is identical.
Revisit the error report's stack trace and cross-reference with the code to find the specific lines at fault.
index.js
around the line number called out in the stack trace shown in the logs: main.py
around the line number called out in the stack trace shown in the logs: Find the source of the error message in the file main.go
around the line number called out in the stack trace shown in the logs:
Find the source of the error message in the file App.java
around the line number called out in the stack trace shown in the logs:
Examining this code, the following actions are taken when the NAME
environment variable is not set:
The problem is caused by a missing variable, but the root cause is more specific: the code change adding the hard dependency on an environment variable did not include related changes to deployment scripts and runtime requirements documentation.
Now that we have collected the code and identified the potential root cause, we can take steps to fix it.
Check whether the service works locally with the NAME
environment available in place:
Run the container locally with the environment variable added:
PORT=8080&&dockerrun--rm-ePORT=$PORT-p9000:$PORT\-eNAME="Local World!"\gcr.io/PROJECT_ID/hello-service
Navigate your browser to http://localhost:9000
See "Hello Local World!" appear on the page
Modify the running Cloud Run service environment to include this variable:
Run the services update command to add an environment variable:
gcloudrunservicesupdatehello-service\ --set-env-varsNAME=Override
Wait a few seconds while Cloud Run creates a new revision based on the previous revision with the new environment variable added.
Confirm the service is now fixed:
In this sample production problem, the error was related to operational configuration. There are code changes that will minimize the impact of this problem in the future.
Let's step through removing the NAME
environment variable as a hard dependency.
Remove the existing NAME
-handling code:
Add new code that sets a fallback value:
Test locally by re-building and running the container through the affected configuration cases:
dockerbuild--taggcr.io/PROJECT_ID/hello-service.
dockerbuild--taggcr.io/PROJECT_ID/hello-service.
dockerbuild--taggcr.io/PROJECT_ID/hello-service.
mvncompilejib:build
Confirm the NAME
environment variable still works:
PORT=8080&&dockerrun--rm-ePORT=$PORT-p9000:$PORT\-eNAME="Robust World"\gcr.io/PROJECT_ID/hello-service
Confirm the service works without the NAME
variable:
PORT=8080&&dockerrun--rm-ePORT=$PORT-p9000:$PORT\gcr.io/PROJECT_ID/hello-service
If the service does not return a result, confirm the removal of code in the first step did not remove extra lines, such as those used to write the response.
Deploy this by revisiting the Deploy your code section.
Each deployment to a service creates a new revision and automatically starts serving traffic when ready.
To clear the environment variables set earlier:
gcloud run services update hello-service --clear-env-vars
Add the new functionality for the default value to automated test coverage for the service.
You may see other issues in the Log Viewer for this service. For example, an unsupported system call will appear in the logs as a "Container Sandbox Limitation".
For example, the Node.js services sometimes result in this log message:
Container Sandbox Limitation: Unsupported syscall statx(0xffffff9c,0x3e1ba8e86d88,0x0,0xfff,0x3e1ba8e86970,0x3e1ba8e86a90). Please, refer to https://gvisor.dev/c/linux/amd64/statx for more information.
In this case, the lack of support does not impact the hello-service sample service.
For Terraform-related troubleshooting or questions, see Terraform policy validation troubleshooting or contact Terraform support.
If you created a new project for this tutorial, delete the project. If you used an existing project and wish to keep it without the changes added in this tutorial, delete resources created for the tutorial.
The easiest way to eliminate billing is to delete the project that you created for the tutorial.
To delete the project:
Delete the Cloud Run service you deployed in this tutorial:
gcloudrunservicesdeleteSERVICE-NAME
Where SERVICE-NAME is your chosen service name.
You can also delete Cloud Run services from the Google Cloud console.
Remove the gcloud default region configuration you added during tutorial setup:
gcloudconfigunsetrun/region
Remove the project configuration:
gcloud config unset project
Delete other Google Cloud resources created in this tutorial:
gcr.io/<var>PROJECT_ID</var>/hello-service
from Container Registry.Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-17 UTC.