[[["易于理解","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。"],[[["\u003cp\u003eThis page details best practices for building and managing container images, which directly impacts build and deployment speed, as well as maintenance efforts.\u003c/p\u003e\n"],["\u003cp\u003eWhen using images from public sources, it is recommended to build your own, use a standardized base image, scan for vulnerabilities, and enforce deployment policies to enhance security.\u003c/p\u003e\n"],["\u003cp\u003eBefore making registries public, ensure images are shareable, be aware of network egress costs, and consider capping per-user quota to prevent abuse.\u003c/p\u003e\n"],["\u003cp\u003eRemoving unused container images helps reduce storage costs and mitigate risks associated with using outdated software.\u003c/p\u003e\n"],["\u003cp\u003eUtilizing tools like Docker Bench for Security can help assess and improve the security of Docker containers, though some aspects require manual verification.\u003c/p\u003e\n"]]],[],null,["# Best practices for containers\n\nThis page provides information about best practices for building and running\ncontainer images.\n\nBuilding containers\n-------------------\n\nThe approach that you take to building container images can impact the\nspeed of builds and deployments, as well as the effort required to maintain\nyour images.\n\nRead the [Docker best practices](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) for building images.\n\nConsiderations for public registries\n------------------------------------\n\nCarefully consider the following cases:\n\nUsing images from public sources\n\n: When you use images from public sources such as Docker Hub, you are\n introducing code that your organization does not control into your software\n supply chain. To mitigate risk, you can:\n\n - Build your own images to control image content.\n - Use a standardized base image and build on top of that image.\n - Scan images for vulnerabilities and address identified vulnerabilities.\n - Enforce standards and policies on images you deploy.\n\nMaking your registries public\n\n: You can make the registry in your Google Cloud project public by granting\n read access on the registry storage bucket to the `allUsers` identity.\n\n If all your users have Google Cloud accounts, you can limit access\n to authenticated users with the `allAuthenticatedUsers` identity instead.\n\n Consider the following guidelines before making a registry public:\n\n - Verify that all images you store in the registry are sharable publicly and do not expose credentials, personal data, or confidential data.\n - You are charged for [network egress](/container-registry/docs/pricing) when users pull images. If you expect a lot of internet download traffic, consider the associated costs.\n - By default, projects have unlimited per-user [quota](/container-registry/quotas). To prevent abuse, [cap](/docs/quotas/view-manage#capping_usage) per-user quotas within your project.\n\nRemoving unused images\n----------------------\n\nRemove unused container images to reduce storage costs and mitigate the risks of\nusing older software. There are a number of tools available to help with\nthis task, including [gcr-cleaner](https://github.com/sethvargo/gcr-cleaner). The gcr-cleaner tool is not an official Google product.\n| **Warning:** Do not use Cloud Storage \\[object lifecycle management\\] with Container Registry storage buckets. Lifecycle management does not work with images stored in Container Registry.\n\nAssessing container security\n----------------------------\n\nThe Center for Internet Security (CIS) has a [Docker Benchmark](https://www.cisecurity.org/benchmark/docker/) for evaluating\nthe security of a Docker container.\n\nDocker provides an open source script called [Docker Bench for Security](https://github.com/docker/docker-bench-security).\nYou can use the script to validate a running Docker container against the CIS\nDocker Benchmark.\n\nDocker Bench For Security can help you verify many items in the CIS Docker\nBenchmark, but not all items are verifiable with the script.\nFor example, the script cannot verify if the host for the container is hardened\nor if the container image includes personal data. Review all items in the\nbenchmark and identify those that might need additional verification.\n\nSecuring deployments\n--------------------\n\nLearn about building a [secure software supply chain](/software-supply-chain-security/docs/overview) and\nhow to use vulnerability scanning and Binary Authorization on Google Cloud to define\nand enforce policies for deployment.\n\nYou can also watch a video that describes securing your software supply chain."]]