diff --git a/docs/tech/Docker-Compose-Limiting-container-resource-usage.md b/docs/tech/Docker-Compose-Limiting-container-resource-usage.md index 1004d21..9a1465f 100644 --- a/docs/tech/Docker-Compose-Limiting-container-resource-usage.md +++ b/docs/tech/Docker-Compose-Limiting-container-resource-usage.md @@ -2,41 +2,22 @@ ## 修改 docker-compose.yml -限制资源配置字段为 `deploy.resources.limits`,以下是示例 docker-compose.yml +运用 compose 组件可限制容器的资源使用,以下是示例 docker-compose.yml ``` yaml title="docker-compose.yml" -version: '3' services: - umami: - image: docker.umami.dev/umami-software/umami:mysql-latest - deploy: - resources: - limits: - cpus: '0.50' - memory: 500M - reservations: - cpus: '0.25' - memory: 200M - ports: - - "3000:3000" - environment: - DATABASE_URL: mysql://umami:xxx@127.0.0.1:3306/umami - DATABASE_TYPE: mysql - HASH_SALT: replace-me-with-a-random-string - restart: always - network_mode: "host" + : + image: + ## 可用的 CPU 数 + cpus: 1 + ## 内存大小限制 + mem_limit: 1G ``` -在以上示例中,Umami 容器的 CPU 使用限制在 25%-50%,内存使用限制在 200MB-500MB。 - -## 修改 docker compose 启动命令 - -传入参数 `--compatibility` 表示以兼容模式来运行 - -``` bash -docker compose --compatibility up -d -``` +在以上示例中,容器的 CPU 使用数限制在1个,内存使用限制在1G。 ## 参考 -[如何在Docker Compose中限制容器的CPU和内存使用?](https://blog.xiaoz.org/archives/18729) \ No newline at end of file +[如何在 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) \ No newline at end of file