Files
blog/docs/tech/Docker-Compose-Limiting-container-resource-usage.md
Cat Tom e96f004dae
All checks were successful
Deploy / deploy (push) Successful in 45s
edit Docker-Compose-Limiting-container-resource-usage
2026-01-25 00:24:09 +08:00

23 lines
681 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Docker Compose: 限制容器的资源使用
## 修改 docker-compose.yml
运用 compose 组件可限制容器的资源使用,以下是示例 docker-compose.yml
``` yaml title="docker-compose.yml"
services:
<service_name>:
image: <image_path>
## 可用的 CPU 数
cpus: 1
## 内存大小限制
mem_limit: 1G
```
在以上示例中,容器的 CPU 使用数限制在1个内存使用限制在1G。
## 参考
[如何在 docker compose file 中限制系統資源的使用 - Zen's Blog](https://www.zenwen.tw/docker-compose-file-limit-resource)
[Define services in Docker Compose - Docker Docs](https://docs.docker.com/reference/compose-file/services)