docker container 动态修改内存限制

docker动态修改配置用docker update,用法:

docker update -h
Flag shorthand -h has been deprecated, please use --help
 
Usage:	docker update [OPTIONS] CONTAINER [CONTAINER...]
 
Update configuration of one or more containers
 
Options:
      --blkio-weight uint16         Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
      --cpu-period int              Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int               Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int           Limit the CPU real-time period in microseconds
      --cpu-rt-runtime int          Limit the CPU real-time runtime in microseconds
  -c, --cpu-shares int              CPU shares (relative weight)
      --cpuset-cpus string          CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string          MEMs in which to allow execution (0-3, 0,1)
      --help                        Print usage
      --kernel-memory string        Kernel memory limit
  -m, --memory string               Memory limit
      --memory-reservation string   Memory soft limit
      --memory-swap string          Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --restart string              Restart policy to apply when a container exits
 

当前要做的是把一个运行着gitlab 的容器内存限制在2048M以内,尝试用:

docker update -m 2048m gitlab

报错:

 Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same time

发现问题,docker 默认没有启用memory-swap交换内存,直接设置了内存会出问题,也就是说宿主 swap 支持使用多少则容器即可使用多少,如果 --memory-swap 设置小于 --memory则设置不生效。

将memory-swap 设置值为 -1,表示容器程序使用内存受限,而 swap 空间使用不受限制。

docker update --memory 2048m --memory-swap -1 gitlab

问题解决。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值