[[["易于理解","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-08-25。"],[],[],null,["# About service execution environments\n\n*Cloud Run services* by default don't have an execution environment\nspecified, which means Cloud Run selects the execution environment\nbased on the features used. So unless you specify an execution environment for\nyour service, Cloud Run can select either the first\ngeneration or second generation environment.\n\nNote that Cloud Run jobs only use the second generation\nexecution environment, and this cannot be changed for jobs.\n\nThe first generation execution environment features fast [cold start](/run/docs/tips/general#using_minimum_instances_to_reduce_cold_starts) times and emulation of\nmost, but not all operating system calls. Originally, this was the only\nexecution environment available to services in Cloud Run.\n\nThe second generation execution environment provides full\nLinux compatibility rather than system call emulation. This execution environment\nprovides:\n\n- Faster CPU performance\n- Faster network performance, especially in the presence of packet loss\n- Full Linux compatibility, including support for all system calls, namespaces, and cgroups\n- Network file system support\n\n| **Important:** Cloud Run jobs automatically use the second generation execution environment, and this cannot be changed for jobs.\n\nAlthough the second generation execution environment generally performs faster\nunder sustained load, it has longer [cold start times](/run/docs/tips/general#starting_services_quickly)\nthan first generation for most services.\n\nHow to choose an execution environment\n--------------------------------------\n\nYou should use first generation if any of the following apply:\n\n- Your Cloud Run service has bursty traffic, and needs to scale out fast to many instances, or your service is sensitive to cold start times.\n- Your Cloud Run service has infrequent traffic that causes frequent scale out from zero.\n- You want to use less than 512 MiB of memory. The second generation execution environment requires at least 512 MiB of memory.\n\nYou should use second generation if any of the following apply to your\nCloud Run service:\n\n- Your service needs to use NFS, which is only supported by second generation.\n- Your service has fairly steady traffic and is tolerant of somewhat slower cold starts.\n- Your service has CPU-intensive workloads.\n- Your service could benefit from faster network performance.\n- Your service needs to use software that has issues running in first generation due to [unimplemented system calls](/run/docs/troubleshooting#openblas-warning).\n- Your service needs Linux cgroup functionality.\n- Your service makes use of third-party infrastructure for securing containers.\n\nBest practices when using the second generation execution environment\n---------------------------------------------------------------------\n\nWe recommend that your container install a [SIGTERM handler](/run/docs/container-contract#instance-shutdown),\nespecially if you are using\n[request-based billing](/run/docs/configuring/billing-settings).\n\nHandling SIGTERM gives your container a chance to perform any necessary cleanup\ntasks such as flushing logs before exiting. If your container does not catch\nSIGTERM, it will still be given 10 seconds to perform these tasks; those 10\nseconds are billable.\n\n### How to check whether your container handles SIGTERM\n\nTo determine whether your container has a SIGTERM handler installed:\n\n1. Start Cloud Shell. You can find\n\n **Activate Cloud Shell** in the header of the documentation\n page you're on. You may need to authorize it and wait for it to provision.\n Alternatively, [start a standalone session](/shell/docs/launching-cloud-shell#launch_a_standalone_session).\n\n2. Run the container locally in Cloud Shell:\n\n ```\n docker run IMAGE_URL\n ```\n\n Replace \u003cvar translate=\"no\"\u003eIMAGE_URL\u003c/var\u003e with a reference to the container image, for\n example, `us-docker.pkg.dev/cloudrun/container/hello:latest`. If you use Artifact Registry,\n the [repository](/artifact-registry/docs/repositories/create-repos#docker) \u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e must\n already be created. The URL follows the format of \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e`-docker.pkg.dev/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003eREPO_NAME\u003c/var\u003e`/`\u003cvar translate=\"no\"\u003ePATH\u003c/var\u003e`:`\u003cvar translate=\"no\"\u003eTAG\u003c/var\u003e\n .\n3. Open another tab in Cloud Shell and get a list of the containers running\n in the current Cloud Shell session:\n\n ```\n docker container ls\n ```\n\n You need to locate the container ID returned from the command.\n4. Using the container ID, send your container a SIGTERM signal\n\n ```\n docker kill -s SIGTERM CONTAINER_ID\n ```\n5. Return to the tab where you invoked `docker run` to see whether the container\n has exited (stopped). If the SIGTERM signal caused your container to exit, your\n container is handling SIGTERM.\n\n### How to handle SIGTERM\n\nIf your container does not handle SIGTERM, the simplest way to add a SIGTERM\nhandler is to wrap your service with `tini`. Doing this makes your service run\nas a subprocess of `tini`, which takes on the role of the container init process.\nRefer to the [Docker instructions](https://github.com/docker-library/official-images#init)\nfor instructions.\n\nAlternatively, you can change your application to directly handle SIGTERM.\n\nWhat's next\n-----------\n\n- To specify an execution environment for your Cloud Run services, refer to [Select an execution environment](/run/docs/configuring/execution-environments).\n- To specify memory for your for your Cloud Run services, refer to [Memory limits](/run/docs/configuring/services/memory-limits).\n- To use Filestore with Cloud Run, refer to [Using Filestore with Cloud Run](/run/docs/tutorials/network-filesystems-filestore).\n- To use Cloud Storage FUSE with Cloud Run, refer to [Using Cloud Storage FUSE with Cloud Run](/run/docs/tutorials/network-filesystems-fuse)."]]