From bced53410d30b83b4fa741ecb74fe9950ff40dba Mon Sep 17 00:00:00 2001 From: Cat Tom Date: Thu, 25 Jul 2024 19:11:03 +0800 Subject: [PATCH] add --- ...mpose-Limiting-container-resource-usage.md | 38 +++++++++++++++++++ mkdocs.yml | 3 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 docs/tech/Docker-Compose-Limiting-container-resource-usage.md diff --git a/docs/tech/Docker-Compose-Limiting-container-resource-usage.md b/docs/tech/Docker-Compose-Limiting-container-resource-usage.md new file mode 100644 index 0000000..65d5f4e --- /dev/null +++ b/docs/tech/Docker-Compose-Limiting-container-resource-usage.md @@ -0,0 +1,38 @@ +# Docker Compose: 限制容器的资源使用 + +## 修改 docker-compose.yml + +限制资源配置字段为 `deploy.resources.limits`,以下是示例 docker-compose.yml + +``` 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" +``` + +在以上示例中,Umami 容器的 CPU 使用限制在 25%-50%,内存使用限制在 200MB-500MB。 + +## 修改 docker compose 启动命令 + +传入参数 `--compatibility` 表示以兼容模式来运行 + +```bash +docker compose --compatibility up -d +``` \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index ec349b1..201f639 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -79,9 +79,10 @@ nav: - tech/index.md - "Mi 6 (sagit)": tech/Mi6(sagit).md - "极1S (HC5661)": tech/HC5661.md - - "Redmi 4X (santoni)": tech/Redmi4X(santoni).md - "Git: 覆盖本地修改": tech/Git-overwriting-local-changes.md + - "Redmi 4X (santoni)": tech/Redmi4X(santoni).md - "手把手教你备份和还原 Docker 卷": tech/Backup-and-Restore-of-Docker-Volumes-A-Step-by-Step-Guide.md + - "Docker Compose: 限制容器的资源使用": tech/Docker-Compose-Limiting-container-resource-usage.md - "创建和管理 Linux 服务器用于身份验证的 SSH 密钥": tech/Creating-and-Managing-SSH-Keys-for-Authentication-on-Linux-Servers.md - "MkDocs 参考": examples/index.md