docker动态修改容器限制

动态修改配置用docker update

语法介绍

[root@localhost ~]# docker update --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)
      --cpus decimal               Number of CPUs
      --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)
      --kernel-memory bytes        Kernel memory limit
  -m, --memory bytes               Memory limit
      --memory-reservation bytes   Memory soft limit
      --memory-swap bytes          Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --restart string             Restart policy to apply when a container exits

可以通过docker stats 查看当前容器情况

docker stats --no-stream    添加 --no-stream参数,不会实时刷新显示资源使用情况。

docker stats 显示全部容器

docker stats containername 显示指定容器

现在试验修改mongodb的内存限制

操作失败了,提示信息:内存限制应小于已设置的memoryswap限制,同时更新memoryswap

注意:

指定限制内存大小并且设置 memory-swap 值为 -1,表示容器程序使用内存受限,而 swap 空间使用不受限制,宿主 swap 支持使用多少则容器即可使用多少。

如果不添加–memory-swap选项,则表示容器中程序可以使用8G内存和8Gswap内存,默认情况下,–memory-swap 会被设置成 memory 的 2倍。-m 为物理内存上限,而 –memory-swap 则是 memory + swap 之和,当压测值是 –memory-swap 上限时,则容器中的进程会被直接 OOM kill。

 

posted @ 2021-12-31 09:36  芝幽幽  阅读(908)  评论(0编辑  收藏  举报