[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Developing your service\n\nThis page describes a few things you need to know to get started in developing\na service for Cloud Run.\n\nCode requirements\n-----------------\n\nYou must meet the following requirements when you develop a service:\n\n- The service must listen for requests. You can [configure the port](/run/docs/configuring/services/containers#configure-port) on which requests are sent. Inside Cloud Run instances, the value of the `PORT` environment variable always reflects the port to which requests are sent. Your code should check for the existence of this `PORT` environment variable and if it is present, should listen on it to maximize portability.\n- The service must be *stateless* . It cannot rely on a persistent **local** state.\n- If the service performs background activities outside the scope of request handling it must use the [instance-based billing](/run/docs/configuring/billing-settings#choosing-background-execution) setting in order to have CPU allocated outside of the standard request cycle.\n- If your service uses NFS, it must use the [second generation execution environment](/run/docs/about-execution-environments).\n\nYou can find more details about these constraints in the [Container runtime contract](/run/docs/reference/container-contract).\n\nProgramming language support\n----------------------------\n\nCloud Run source deployment conveniently supports multiple\n[language runtimes](/run/docs/configuring/services/runtime-base-images), each of\nwhich is available through container base images provided by\nGoogle Cloud's buildpacks. You can also use other programming languages or\nframeworks, as long as the source code is in an OCI-compliant image.\n\nThe [build and deploy quickstarts](/run/docs/quickstarts#build-and-deploy-a-web-service)\nprovides samples in many popular languages.\n\nUsing a web server\n------------------\n\nYou can use a web server to listen on the required port, and to process and\nroute incoming requests. For example, Node.js developers can use\n[Express.js](https://expressjs.com/), Python developers can use\n[Flask](http://flask.pocoo.org/), Ruby developers can use\n[Sinatra](http://sinatrarb.com/), and so forth.\n\nContainerizing your code\n------------------------\n\nSee [Containerize your code](/run/docs/building/containerize-your-code) for\ndetails.\n\nDesign Cloud Run apps with Gemini assistance\n--------------------------------------------\n\n\u003cbr /\u003e\n\n|\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nYou can get AI-powered help from\n[Gemini Cloud Assist](/gemini/docs/cloud-assist/overview) chat to\ndesign applications optimally. With Gemini Cloud Assist, you can\ndiscover the most suitable configurations and strategies for deploying your\napplications on Cloud Run, ensuring efficient resource\nutilization and seamless operation.\n\nTo use Gemini Cloud Assist from the Google Cloud console, do\nthe following:\n\n1. [Ensure that Gemini Cloud Assist is set up for your Google Cloud user account and project](/gemini/docs/cloud-assist/set-up-gemini).\n\n2. [Set up your Cloud Run development environment](/run/docs/setup)\n in your Google Cloud project and ensure you have the appropriate\n [deployment permissions](/run/docs/reference/iam/roles#additional-configuration).\n\n3. Go to the Cloud Run page in the Google Cloud console.\n\n [Go to Cloud Run](https://console.cloud.google.com/run)\n4. In the console toolbar, select a Google Cloud project. Use a project\n associated with a project ID you submitted after you were granted access to\n Gemini Cloud Assist.\n\n5. Click spark\n **Open or close Gemini AI chat**.\n\n The Gemini panel opens.\n6. If necessary, click **Accept** if you agree to the terms.\n\n7. If you have a question about a specific application, provide context by\n going to the page that shows your resource before asking your question. When\n generating a response, Gemini includes information about the\n current console page and project.\n\n8. Enter a prompt in the **Gemini** panel.\n\n The following table provide some example prompts for using\n Gemini Cloud Assist with Cloud Run.\n\nFor more details, see the following resources:\n\n- Learn how to [write better prompts](/gemini/docs/discover/write-prompts).\n- Learn how to use the [Gemini Cloud Assist panel](/gemini/docs/cloud-assist-panel).\n- Read [Use Gemini for AI assistance and development](/gemini/docs/overview).\n- Learn [how Gemini for Google Cloud uses your data](/gemini/docs/discover/data-governance).\n\nWhat's next\n-----------\n\n- Once you have your service code and Dockerfile, you should [build a container image](/run/docs/building/containers) then continue iterating in [local testing](/run/docs/testing/local).\n- If you are migrating an existing web application, see [Migrating Your Service to Cloud Run](/run/docs/migrating).\n- For best practices for designing, implementing, testing, and deploying a Cloud Run service, see the [Development tips](/run/docs/tips)."]]