:feature: 添加容器内存限制配置,默认值设置为512MB
Some checks failed
BuildImage / build-image (push) Has been cancelled

This commit is contained in:
李寻欢 2025-04-22 21:21:06 +08:00
parent 963ae62367
commit 4ca9c5e2d7
4 changed files with 7 additions and 0 deletions

View File

@ -18,6 +18,7 @@ docker:
apiVersion: "1.41"
imageName: "lxh01/xybotv2:latest"
network: "bridge"
memory: 123 # 容器内存限制MB
redis:
host: "10.0.0.31"
password: "pGhQKwj7DE7FbFL1"

View File

@ -33,6 +33,7 @@ docker:
apiVersion: "1.41"
imageName: "lxh01/xybotv2:latest"
network: "bridge"
memory: 123 # 容器内存限制MB
redis:
host: "10.0.0.31"
password: "pGhQKwj7DE7FbFL1"

View File

@ -17,6 +17,7 @@ type DockerConfig struct {
APIVersion string `mapstructure:"apiVersion"` // Docker API版本
ImageName string `mapstructure:"imageName"` // 微信机器人Docker镜像名称
Network string `mapstructure:"network"` // 容器网络
Memory int64 `mapstructure:"memory"` // 内存限制
Redis RedisConfig `mapstructure:"redis"` // Redis配置
}

View File

@ -100,6 +100,10 @@ func CreateContainer(ctx context.Context, cfg *config.DockerConfig, name string,
Name: "unless-stopped",
},
}
if cfg.Memory == 0 {
cfg.Memory = 512 // 默认内存限制为512M
}
hostConfig.Memory = cfg.Memory * 1024 * 1024 // 限制使用内存
// 设置网络配置
networkingConfig := &network.NetworkingConfig{}