edit Docker-Compose-Limiting-container-resource-usage
All checks were successful
Deploy / deploy (push) Successful in 45s
All checks were successful
Deploy / deploy (push) Successful in 45s
This commit is contained in:
@@ -2,41 +2,22 @@
|
|||||||
|
|
||||||
## 修改 docker-compose.yml
|
## 修改 docker-compose.yml
|
||||||
|
|
||||||
限制资源配置字段为 `deploy.resources.limits`,以下是示例 docker-compose.yml
|
运用 compose 组件可限制容器的资源使用,以下是示例 docker-compose.yml
|
||||||
|
|
||||||
``` yaml title="docker-compose.yml"
|
``` yaml title="docker-compose.yml"
|
||||||
version: '3'
|
|
||||||
services:
|
services:
|
||||||
umami:
|
<service_name>:
|
||||||
image: docker.umami.dev/umami-software/umami:mysql-latest
|
image: <image_path>
|
||||||
deploy:
|
## 可用的 CPU 数
|
||||||
resources:
|
cpus: 1
|
||||||
limits:
|
## 内存大小限制
|
||||||
cpus: '0.50'
|
mem_limit: 1G
|
||||||
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。
|
在以上示例中,容器的 CPU 使用数限制在1个,内存使用限制在1G。
|
||||||
|
|
||||||
## 修改 docker compose 启动命令
|
|
||||||
|
|
||||||
传入参数 `--compatibility` 表示以兼容模式来运行
|
|
||||||
|
|
||||||
``` bash
|
|
||||||
docker compose --compatibility up -d
|
|
||||||
```
|
|
||||||
|
|
||||||
## 参考
|
## 参考
|
||||||
|
|
||||||
[如何在Docker Compose中限制容器的CPU和内存使用?](https://blog.xiaoz.org/archives/18729)
|
[如何在 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)
|
||||||
Reference in New Issue
Block a user